首页 > 代码库 > python第一天
python第一天
在pycharm中设置程序模板:
#!usr/bin/env python #声明环境变量 ,Windows不需要 #-*- coding:utf-8-*- # Author burnywen
变量:
name = "burnywen" print("burnywen")
name = "burnywen" name2 = name print(name,name2) name = "banana" #name2直接指向burnywen,不随name改变而改变 print(name,name2) 输出: burnywen burnywen banana burnywen
二进制:
十进制:130 128 64 32 16 8 4 2 1 二进制 1 0 0 0 0 0 1 0
ASCII:
十进制 | 对应字符 |
48—57 | 0—9 |
65—90 | A—Z |
97—122 | a—z |
格式化:
name = input("name:") age =int(input("age:")) #转换为integer job = input("job:") salary = int(input("salary:")) info = """ ----------info of %s------------ name:%s age:%d job:%s salary:%d """%s(name,name,age,job,salary ) print(info) info2 = """ #特定场景下只能用这种 ----------info of {_name}------------ name:{_name} age:{_age} job:{_job} salary:{_salary} """.format(_name = name, _age = age, _job = job, _salary = salary) print(info2) info3 = """ ----------info of {0}------------ name:{0} age:{1} job:{2} salary:{3} """.format(name,age,job,salary) print(info3)
guess_age小游戏:
#!usr/bin/env python #-*- coding:utf-8-*- # Author burnywen age_of_burnywen = 23 count = 0 while count <3: age = int(input("guess age:")) if age == age_of_burnywen: print("you are right") break elif age > age_of_burnywen: print("think smaller...") else: print("think bigger...") count += 1 if count ==3: retry = input("do you want to try? y/n") if retry != "n": count=0 continue else: print("end...")
python第一天
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。