python基础,,#第一个python


#第一个python程序
技术分享图片
#第一个python程序# print(‘hello world‘)# print(‘你好,世界‘)
View Code
#变量的命名
技术分享图片
#变量的命名# AgeOfAlex=18#驼峰体# age_of_alex=18#下划线
View Code
#内存空间
技术分享图片
#内存空间# a=20# b=a# a=10# print(a,b)
View Code
#引号的使用
技术分享图片
#引号的使用# print(‘I am a student‘)# print("I‘m a student")# msg="""# 会当凌绝顶,# 一览众山小。# """# print(msg)
View Code
#字符串的拼接
技术分享图片
#字符串的拼接# print(‘alex‘+‘wusir‘)# print(‘alex‘*4)
View Code
#input 用户交互  得到的是字符串
技术分享图片
#input 用户交互  得到的是字符串# name=input("name:")# password=input("password:")# print(name,password)# print(type(name),type(password))
View Code
#条件控制语句 if elif else
技术分享图片
#条件控制语句 if elif else# score=int(input("请输入成绩:"))# if score>=90:#     print(‘A‘)# elif score>=80:#     print(‘B‘)# elif score>=70:#     print(‘C‘)# else:#     print(‘D‘)#嵌套使用# name=input("name:")# age=int(input("age:"))# if name==‘alex‘:#     if age==18:#         print(‘welcome‘)#     else:#         print(‘age error‘)# else:#     print(‘name error‘)
View Code
# while循环
技术分享图片
# while循环# 死循环# while True:#     print(‘hello‘)#输出1-100# count=1# while count<=100:#     print(count)#     count+=1#计算1-100的和# s=0# count=1# while count<=100:#     s+=count#     count+=1# print(s)
View Code
#break跳出循环
#continue跳出本次循环 继续下一次循环
#else循环正常执行完毕才执行
技术分享图片
#break跳出循环#continue跳出本次循环 继续下一次循环#else循环正常执行完毕才执行# count=1# while True:#     print(count)#     count+=1#     if count>100:#         break# else:#     print(‘循环正常执行完了才执行‘)# print(‘--------end--------‘)#输出1-5 95-100# count=0# while count<100:#     count+=1#     if count>5 and count<95:#         continue#     else:#         print(count)
View Code
#标志位
技术分享图片
#标志位 输出1-100# flag=True# count=1# while flag:#     print(count)#     if count==100:#         flag=False#     count+=1
View Code
#格式化输出 %s %d %%
技术分享图片
#格式化输出 %s %d# name=input(‘name:‘)# age=int(input(‘age:‘))# hobby=input(‘hobby:‘)# msg="""# -----info of %s-----# name:%s# age:%d# hobby:%s# ---------end----------# """%(name,name,age,hobby)# print(msg)#%%# print(‘%s的数学成绩占20%%‘%(‘alex‘))
View Code








python基础

评论关闭