c语言sscanf函数的用法是什么
247
2022-09-04
Python的简单语法(一)
import sysa=3b=4c=5.66d=8.0e=complex(c,d)f=complex(float(a),float(b))print("a is type:",type(a))print("c is type:",type(c))print("e is type:",type(e))print(sys.float_info)age=3name="sunliyuan"print("{0} was {1} years old".format(name, age))'''保证所有的变量都是字符串'''print(name+"was"+ str(age) +" years old")
List结构列表:
#创建listnumber_list=[1,3,5,7,9]print("number_list:"+ str(number_list))string_list=["abc","bbc","python"]#创建混合的元素列表mixed_list=["python",".net",3,12]print("string_list"+str(string_list))print("mixed_list"+ str(mixed_list))#访问列表中的second_num=number_list[1]third_string=string_list[2]fourth_mixed=mixed_list[3]print("second_num:{0} third_string:{1} fourth_mixed:{2}".format(second_num,third_string,fourth_mixed)) #更新列表中的元素number_list[1]=30print("number_list after: "+str(number_list))#删除list 的元素del number_list[1]print("number_list after del: "+ str(number_list))#判断是否在元素内print(len([1,2,3]))print([1,2,3]+[4,5,6])print(['Hellow']* 4)print(3 in [1,2,3])abcd_list=['a','b','c','d']print(abcd_list[1])#除右边数print(abcd_list[-2])#: 代表剩下的所有元素print(abcd_list[1:])
换行:
print("what's your name? \n Tom")
Tuple:一旦创建不能修改
number_tuple=(1,3,5,7,9)print("number_list:"+ str(number_tuple))string_tuple=("abc","bbc","python")mixed_tuple=("python",".net",3,12)print("number_list:"+ str(number_tuple))print("string_list"+str(string_tuple))print("mixed_list"+ str(mixed_tuple))#Tuple(元组)一旦被创建就不可以更改 List可以#删除 Tuple不可以删除其中的元素 但是可以删除整个Tupledel mixed_tuple#打印长度print(len((1,2,3)))print((1,2,3)+(4,5,6))print(('Hellow') * 4)print(3 in (1,2,3))abcd_list=('a','b','c','d')print(abcd_list[1])#除右边数print(abcd_list[-2])#: 代表剩下的所有元素print(abcd_list[1:])
Tuple和List
#创建只包含一个元素的tuplea_tuple=(2,)#Tuple中的listmixed_tuple=(1,2,['a','b'])print("mixed_tuple: " +str(mixed_tuple))#更改tuple中的listmixed_tuple[2][0]='c'mixed_tuple[2][1]='d'print("mixed_tuple after " +str(mixed_tuple))#Tuple比List操作速度要快。如果定义了一个值得常量集,并且唯一要做的不断地遍历他,使用Tuple代替list Tuple比较安全(不能修改)
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~