python基础知识-python基础知识,python必背内容,一、python的基

python基础知识,python必背内容,一、python的基

一、python的基础

1、简单写一行python代码:print("hello,world’)print("你好,北京’)

2、变量:name="刘梦雅"print(name)

程序交互:name=input"请输入你的名字”print(name)

3、数据类型

(1)int,long类型:a=2*20print(a,type(a))

(2)字符串类型str:name=input("请输入你的名字")print(name,type(name))()

(3)布尔类型:print(true,type(true))

4、if语句choice=input("请输入你猜的数字’)if choice=="2’ print("我请你吃饭’)else print("你请我吃饭’)

5、while语句

flag = true;count =1;while flag: print(count);

6、break语句:count=1while true: print(count) count=count+1 if count==101 break

7、continue语句count=0 while count<10; count =count +1if count ==7;continue ;print(count )

8、in not in的用法:comment =input("请输入你的评论’) if "傻子’ in comment: print ("您输入的为敏感词汇,请重新输入’)

9、while else

14415H512-0.gifcount = 1while True: print (count ) if count == 3:break count +=1else print("循环正常")

14415H512-0.gif

输出 1

2

3

14415H512-0.gifcount =1flag = Truewhile flag : print (count) if count == 3: flag=False count+=1else : print ("循环正常完毕")

14415H512-0.gif

输出:1

2

3

循环正常完毕

10、格式化输出:

1)第一种name=input("请输入你的名字:’)age =input("请输入你的年龄:’)hobby=input("请输入你的爱好:’)ms ="我叫%s,今年%d,爱好是%s’ % (name,int(age),hobby)print(ms)

2)第二种dic = {"name’:"oldboy","age":15,"hobby":"踢足球"}msg="我叫%(name)s,今年%(age)d,爱好是%(hobby)s’ % dicprint(msg)

3)第三种

再格式化输出中单纯的显示% 用%%解决name=input("请输入你的名字:’)age =input("请输入你的年龄:’)msg="我叫%s,今年%d,学习进度为1%%’ % (name,int(age))print(msg)

11、运算符print(int(True))print (int(False)) 输出:1 0 Trueprint(bool(100))

and or notprint (1 or 3) 输出 1print (1 and 3 ) 3print (0 or 2) 2print(0 and 2) 0print (1>2 or 3 and 4) 4

python基础知识

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值