python基础学习

来源:互联网 发布:女生做淘宝美工累吗 编辑:程序博客网 时间:2024/06/03 22:41

hello world:

message_1 = "hello python"message_2 ="world!"num=2333 #no chinese  this is zhu shi#no chinesemessage_full=message_1+" "+message_2+str(num)print(message_full.title())

list:

EDG=['meiko','scout','zet',"deft"]print(EDG)del EDG[3]print(EDG)EDG.append("mouse")print(EDG)EDG.insert(1,"clearlove")print(EDG)print(EDG[0].title())print(EDG[-1].title())message="i think "+EDG[0]+" is the best sup."print(message.title())EDG.sort()print(EDG)print(len(EDG))

for:

sups=["meiko","five","mata","ming"]for sup in sups:   print(sup+" is god")print("But i think meiko is the best")for value in range(1,5):   print(value)numbers=list(range(1,10,2))print(numbers)squares=[value**3 for value in range(1,11)]print(squares[0:4])

if:

car="Bmw"if car.lower() == "bmw":    print("true")else:    print("false")print(car=="bmw")

else if:

users=["admin","rsin","zhjf","7520"]if users:    for user in users:        if user=="admin":            print("Hello admin,would you like to see a status report?")        else:            print("Hello Eric,think you for logging in again.")else:    print("there is no user")

zidain:

friend ={"name":"chenqiyu","nikename":"xiaoyu","age":20,"city":"beijing"}print(friend)print("not beijing,he is in nanjing")friend["city"]="nanjing"friend["class"]=10print(friend)del friend["class"]print(friend)print(friend["name"]+"("+friend["nikename"]+")"+" in "+friend["city"]+" is "+str(friend["age"])+" years old.")print("*****************************************")for key,value in friend.items():    if key!="age":        print(key+":"+value)    else:        print(key+":"+str(value))print("*****************************************")for key in friend.keys():    print(key)print("*****************************************")for value in friend.values():    print(value)print("*****************************************")alien_0={'color':'green','points':5}alien_1={'color':'yellow','points':10}alien_2={'color':'red','points':15}aliens=[alien_0,alien_1,alien_2]for alien in aliens:    print(alien)

input:

age=input("plz input your age but not in 18~50:")age=int(age)while age>=18 and age<=50:    age=input("plz input your age but not in 18~50:")    age=int(age)if age<18:    print("you are young")elif age>50:    print("you are old")number=0while number<10:    number+=1    if number%2 == 1:        continue    print(number)

function:

def sayhello():    """show hello"""    print("hello")def toyou(name="???"):    """say hello to you"""    print("hello "+name)def make_shirt(cm,cha="rsin"):    print("the shirt with "+cha+" is "+str(cm))def get_plus(a,b):    c=a+b    return cdef get_users(names):    for name in names:        msg="hello, "+name.title()+"!"        print(msg)usernames=["hannah","ty","margot"]get_users(usernames)sayhello()name=input("plz input your name:")toyou(name)cm=input("plz input your cm:")cm=int(cm)make_shirt(cm,name)a=input("plz input a:")a=int(a)b=input("plz input b:")b=int(b)c=get_plus(a,b)print(str(c))

class:

class dog():    def __init__(self,name,age):        self.name=name        self.age=age    def sit(self):        print(self.name.title()+" is sitting now")    def roll_over(self):        print(self.name.title()+" is rolled now")class cutedog(dog):    def __init__(self,name,age):        super().__init__(name,age)my_dog=cutedog('wufan',2)print(my_dog.name.title())print(str(my_dog.age))my_dog.sit()my_dog.roll_over()

file:

with open('D:\pi_digits.txt') as file_object:    contents=file_object.read()    print(contents)print("*******************")with open('D:\pi_digits.txt') as file_object:    for line in file_object:        print(line.rstrip())print("*******************")with open("D:\pi_digits.txt") as file_object:    lines=file_object.readlines()pi_string=''for line in lines:    pi_string+=line.strip()print(pi_string)with open('ok.txt','a') as file_obj:    file_obj.write("hello boys")

dump:

import jsonnumbers=[2,3,5,7,11,13]filename='numbers.json'with open(filename,'w') as f_obj:    json.dump(numbers,f_obj)
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 肉和冰箱冻住了怎么办 解冻的肉臭了怎么办 临时用电电缆线破皮怎么办 阳台按自来水墙面脱落怎么办 墙被暖气熏黑了怎么办 下水管比地砖低怎么办 马桶下水管短了怎么办 下水管比马桶低怎么办? 寻常疣液氮冷冻后该怎么办 寻常疣冷冻后起水泡胀痛怎么办 冷冻后大水泡痒怎么办 19岁的宫颈糜烂怎么办 发面酸了没有碱怎么办 面发时间长酸了怎么办 丽珠兰打完红肿怎么办 美的冰柜冷藏室结冰怎么办 胃下午和晚上痛怎么办 二胡弓毛粗拉外弦触到里弦怎么办 电视成黑白的了怎么办 城市居民无钱入社保医保怎么办 老婆说离婚又找不到怎么办 爱一个人太累了怎么办 车凹陷漏底漆了怎么办 燕子窝掉下来了怎么办 文科没考上一本怎么办 学校午休小学孩子吵闹怎么办 老鼠死在空调里怎么办 公务员老公四十岁想辞职怎么办 打胎5次又怀孕怎么办 墙纸颜色太淡了怎么办 皮子腺囊肿有点疼痛怎么办 地板颜色选浅了怎么办 地板买的太暗了怎么办 木地板贴好后发现颜色不好看怎么办 鞋上鞋扣老是开怎么办 虚拟机的win10蓝屏重启怎么办 fs免拆模板专利怎么办 新买的床咯吱响怎么办 实木床一动就响怎么办 cad图纸是斜的怎么办 老房子土墙腻子老掉怎么办