1. 程式人生 > 其它 >Python基礎快速上手第一章

Python基礎快速上手第一章

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