Python_Day04

  今天是端午,回了家,在车上的时候,又结束了一个视频,算是对之前所学的str方法的一个小总结把。

  最开始就是pycharm的重命名,是shift+F6,和eclipse不一样。

  看了一遍练习题,主要就是下面几个点

  第一个就是.split()和.strip()方法的区别

    .split()的方法是分割

        value = "5+9"
        v1,v2 =value.split("+")
        print(v1)
        print(v1+v2)
        v1 = int(v1)
        v2 = int(v2)
        print(v1+v2)

    以9为分割符,v1的值为“5”,v2的值为“9”,强转为int后相加,输出为5 59 14;

    而.strip()方法是用于移除字符串头尾指定的字符

s = ">>>"
while True:
v1 = input(">>>").strip()
v2 = input(">>>").strip()
v3 = input(">>>").strip()
template = "{0}\t{1}\t{2}\n"
v = template.format(v1, v2, v3)
print(v)
s = s + v
if (v1 == "q" ):
break;
print(s)
    运行结果字符串之间的空间距是一样的
  而第二个方法也是上一段讲述的.format()方法,格式化输出,只是没有加上.strip()方法,间距有出入。
  教学内容和日常的练习难度还是有差距的 ,以后的实战应该差距会更大,来日方长。

猜你喜欢

转载自www.cnblogs.com/ryouki0422/p/10989480.html