python中数有4种类型:
整数
长整数
浮点数:例如52.3E-4
表示52.3 * 10
-4。
复数:(-5+4j)
'''This is a multi-line string. This is the first line.
This is the second line.
"What's your name?," I asked.
He said "Bond, James Bond."
'''
"This is the first sentence.\
This is the second sentence."
相当于:
"This is the first sentence. This is the second sentence."
如果不需要如转义符那样特别处理的字符串,那么需要指定一个自然字符串,自然字符串通过给字符串加上前缀r或者R来指定。例如r"Newlines are indicated by \n"
。
Unicode是书写国际文本的标准方法。若使用中文或者其他文本语言,需要在字符串前加上前缀U或者u。例如: u"这是一个中文字符串";
字符串是不可变的;如果将两个字符串相邻放着,会被python自动级联,例如:'What\'s' 'your name?'
会被自动转为"What's your name?";
标识符命名:变量在命名时需要遵循标识符命名的规则。
通常是数或者字符串,也可以是自己构建的类