本节内容输入输出字符串:
字符串的输入和输出
变量的命名
字符串与数值相乘
数值和字符的转换
字符串是由单引号或双引号括起来的组成的,’\n’在字符串中表示换行,字符串内容可以包含任意字符,三个双引号或单引号可以输入多行字符串
>>> type('python')
<class 'str'>
>>> print("python is a programming \nlanguages")
python is a programming
languages
>>> '''how old are you?
this is a newlines
换新行'''
'how old are you? \nthis is a newlines\n换新行'
>>>
变量(variables)的命名由字母数字下划线构成,且不能以数字开头。
>>> youname = 'admin'
>>> _first_name = 'anonymous'
>>> 23rr = 'er'
File "<stdin>", line 1
23rr = 'er'
^
SyntaxError: invalid syntax
当字符串与数值进行乘法时,print("go"*3 + "let's go!")
,如果数值为0,没有输出。
gogogolet's go!
字符串和数值之间转换int(),和str()
a = int("25")
b = str(25)
print("a=%d"%a) #print("a={}".format(a))
print(type(a))
print(b)
print(type(b))