美文网首页
day01_基础知识学习

day01_基础知识学习

作者: 取名好费劲 | 来源:发表于2021-03-22 09:57 被阅读0次
序列
[start:end:step]   是左闭右开
如果step 是正数 就是从左往右取, 如果step 是负数就是从右往左  
[::-1] 就是将数值反输出

[3:3] 是取空   start < end 
type((1))   ---> int 
type((1,))  --->tuple
a = 'abc'    |   "abc"   | ''' abc '''     
字符串是不可变的  
a = 'abc'
a[1]= e  会报错
字符串格式化
1. " hello %s , you are %d " %("a", 10)
2. " hello {name}  you are {age}".format(name = 'a', age = 10)
3.  a = ['aa', 10]    "hell0 {b[0]}  you are {b[1]}".format(b=a)
4.  a= {'name': 'aa', 'age':10}    "hell0 {b[name]}  you are {b[age]}".format(b=a)
将 I am boy 字符串反输出
a = ' '.join('I am boy'.split()[::-1])
print(a) --> boy am I 

注意审题,错了好多次了

相关文章

网友评论

      本文标题:day01_基础知识学习

      本文链接:https://www.haomeiwen.com/subject/pgdncltx.html