-- 变量
message = "hello python word"
print(message)
-- 练习
vi simple_message.py
#!/usr/bin/python3.4
message = "hello python crash cousor reader!"
print(message)
vi simple_messages.py
messages = "AAAAAA hello python crash cousor reader!"
print(messages)
messages = "BBBBBBB hello python crash cousor reader!"
print(messages)
-- 首字母大写 全部转换为大写 小写
name = "habby yang"
print(name.title())
print(name.upper())
print(name.lower())
-- 连接字符串
fisrt_name = "king"
middle_name = "of"
last_name = "pop"
full_name = fisrt_name + " " + middle_name + " " + last_name
print(full_name)
-- \t 制表符 \n 换行
print("python")
print("\tpython")
print("\npython")
print("\npython\n")
print("languages:\n\tPython\n\tC\n\tJavascript")
-- 删除空白 rstrip() 只能去除开头和结尾的空白 左侧 lstrip() 右侧 rstrip()
habby=" aaa bbb ccc "
habby.lstrip()
habby.rstrip()
habby.lstrip().rstrip()
-- 下面的语句在 Python 3 不能执行 只能在 Python 2 中执行 因为 Python3 将 print() 作为一个函数使用 不能直接打印内容 但是 name.print() 也是不能成功执行的
print "habby"
name = 'habby_yang'
name.print()
name = "habby yang"
world1 = "hello" + " " + name + ",would you like to learn some python today?"
world2 = "hello" + " " + name.title() + ",would you like to learn some python today?"
world3 = "hello" + " " + name.upper() + ",would you like to learn some python today?"
world4 = "hello" + " " + name.lower() + ",would you like to learn some python today?"
print(world1)
print(world2)
print(world3)
print(world4)
print("\n",world1,"\n",world2,"\n",world3,"\n",world4)
>>> print("\n",world1,"\n",world2,"\n",world3,"\n",world4)
hello habby yang,would you like to learn some python today?
hello Habby Yang,would you like to learn some python today?
hello HABBY YANG,would you like to learn some python today?
hello habby yang,would you like to learn some python today?
myworld = 'I said,"my action brings my confidence!"'
print(myworld)
-- 数字的字符转换函数
age = 23
message = "happy " + str(age) + "rd BirsthDay!"
print(message)
print(4+4)
print(12-4)
print(2*4)
print(24/3)
age = 31
message = "happy,you are " + str(age) + " years old!"
print(message)