本章重点:
1.+,-,*,/,//,%,** 是数学操作符,+和*是字符串操作符。
1.print()与 input()函数:输出与输入文本
print('hello world')
print("what is your name?")
my_name = input()
print('here your name is ',my_name)
hello world
what is your name?
bob
here your name is bob
2.len()函数:返回一个整数,为传入字符串的长度,与C语言strlen类似。
print('len of \'hello word\' is' ,len('hello world') )
print('len of your name is', len(my_name))
len of 'hello word' is 11
len of your name is 3
3.str() 、int()和float()函数:传入其他类型的数值,得到字符串,整型或浮点型的值。
a = 25;
b = 'a'
c = 14.14
print('str(25)=' ,str(a))
#print(int(b)) #ValueError: invalid literal for int() with base 10: 'a'
print('float(25) =',float(a))
print('str(14.14)=',str(c))
print('int(14.14)=',int(14))
str(25)= 25
float(25) = 25.0
str(14.14)= 14.14
int(14.14)= 14