Python程序在最開頭需要注明python的路徑
#!/usr/bin/python3Python需要引入使用到的模塊,格式如下:
import sys import mathimport randomimport module1[, module2[,... moduleN]from modname import name1[, name2[, ... nameN]]python中的保留字段如下:
and | exec | not |
assert | finally | or |
break | for | pass |
class | from | |
continue | global | |
def | if | return |
del | import | try |
elif | in | while |
else | is | with |
except | lambda | yield |
print("我是打印的語句")
代碼也可以一行寫多個語句,但是要通過;來區分
text_input=input("/n/nname:");print("input name is:",text_input)對于變量的聲明可以批量聲明.
a=b=c=1 e,f,g=1,2,"123dd" #print(a,b,c,e,f,g)Function | Description |
---|---|
int(x [,base]) | 強制x轉換為整型 |
long(x [,base] ) | 強制x轉換為長整型 |
float(x) | 強制x轉換為浮點型 |
complex(real [,imag]) | 強制x轉換為復數 |
str(x) | 強制x轉換為字符型 |
repr(x) | 強制x轉換為表達式 |
eval(str) | 強制str轉換為指定對象 |
tuple(s) | 強制x轉換為tuple |
list(s) | 強制x轉換為list |
set(s) | 強制x轉換為set類型 |
dict(d) | 強制d轉換為字典型 |
frozenset(s) | 強制s轉換frozen set. |
chr(x) | 強制將整型轉換為字符型 |
unichr(x) | 強制將整型轉換為unicode類型 |
ord(x) | 強制將單字符轉換為整型 |
hex(x) | 將整型轉換為16進制字符串 |
oct(x) | 將整型轉換為8進制字符串 |
包括整型,長整型,浮點型,復雜類型(復數)
新聞熱點
疑難解答