Python数学操作符,优先级从高到低
操作符 | 操作 | 例子 | 求职为 |
** | 指数 | 2 ** 3 | 8 |
% | 取模/取余数 | 22%8 | 6 |
// | 整数/商数取整 | 22//8 | 2 |
/ | 除法 | 22/8 | 2.75 |
* | 乘法 | 3*5 | 15 |
- | 减法 | 5-2 | 3 |
+ | 加法 | 2+2 | 4 |
SyntaxError: invalid syntax
1.2 整形、浮点型、和字符串数据类型
数据类型 | 例子 |
整型 | -2,-1,0,1,2,3,4,5 |
浮点型 | -1.25,-1.0,-0.5,0.0,0.5,1.0 |
字符串 | "a","aa","aaa","Hello!","11 cats" |
# This progrm says hello and asks for my name. print("Hello,world!") print("What is your namr?") # ask for their name myName = input() print("It is good to meet you,"+ myName) print(len(myName)) print("What is your age?") #ask for their age myAge=input() print("You will be" + str(int(myAge)+1)+"in a year.")
inpu()函数
inpu()函数等待用户在键盘上输入一些文本,并按回车键:
myName=inpu()
这个函数的字符串,即用户输入的文本,上面的代码将这个字符串赋值给变量myName。
len()函数
len("Hello") 5