标签:lin support style file 存在 包含 unity code back
什么是变量呢?
>>> message = "Hello,Python!" >>> print (message) Hello,Python!
这里的message就是变量。在程序中可随时修改变量的值,而python将始终记录变量的最新值。
‘I told my friend, "Python is my favorite language!"‘ "The language ‘Python‘ is named after Monty Python, not the snake." "One of Python‘s strengths is its diverse and supportive community."
一些基本的方法
1.title()首字符大写
>>> name = "liu bin" >>> print (name.title()) Liu Bin
2.upper()全部大写转换
>>> name = "liu bin" >>> print (name.upper()) LIU BIN
3.lower()全部小写转换
>>> name = "Liu Bin" >>> print (name.lower()) liu bin
怎么将字符串合在一起呢?
简单的"+"加号既可以实现啦。
>>> first_name = "Bin" >>> last_name = "Liu" >>> full_name = last_name + " " + first_name >>> print (full_name) Liu Bin
制表符和换行符
制表符:\t
>>> print ("python") python >>> print ("\tpython") python
换行符:\n
>>> print ("pythonPHP") pythonPHP >>> print ("python\nPHP") python PHP
怎么删除空白?
运算?
整数加减乘除
>>> 2 + 3 5 >>> 3 - 2 1 >>> 2 * 3 6 >>> 3 / 2 1.5
乘方运算
>>> 3 ** 2 9 >>> 3 ** 3 27 >>> 10 ** 6 1000000
支持括号优先
>>> 2 + 3*4 14 >>> (2 + 3) * 4 20
浮点运算
>>> 0.1 + 0.1 0.2 >>> 0.2 + 0.2 0.4 >>> 2 * 0.1 0.2 >>> 2 * 0.2 0.4
浮点运算结果包含的小数位可能是不确定的,所有语言都会存在这种问题,不用担心,后面有解决方法的
>>> 0.2 + 0.1 0.30000000000000004 >>> 3 * 0.1 0.30000000000000004
非字符串转换为字符串?
>>> age = 23 >>> message = "Happy" + age +"rd Birthday!" Traceback (most recent call last): File "<pyshell#79>", line 1, in <module> message = "Happy" + age +"rd Birthday!" TypeError: must be str, not int
所以用str()转换
>>> message = "Happy " + str(age) + "rd Birthday!" >>> print (message) Happy 23rd Birthday!
注释
Python中使用#注释,换行注释可以使用三引号
# 向大家问好 print("Hello Python people!")
标签:lin support style file 存在 包含 unity code back
原文地址:http://www.cnblogs.com/liubinsh/p/6937409.html