时间:24日下午
输入:input()
输出:print()
格式化输出
通过某种占位符用于替换字符串中某个位置的字符。
占位符:
%s:可以替换任意类型
%d:可以替换数字类型
需要掌握的
#1.strip去左右两边空格lstrip去左边空格,rstrip去右边空格
#2.lower小写,upper大写
eg:print(str1.lower())
#3.startswith,endswith
#4.format(格式化输出)的三种玩法
str1=‘my name is %d,my age %d!‘%(‘ming‘,18)
方式一:print(‘my name is {},my age {}!‘.format(‘ming‘,18))
方式二:print(‘my name is {0},my age {1}!‘.format(‘ming‘,18))
方式三:print(‘my name is {name},my age {age}!‘.format(name=‘ming‘,age=18))
#5.split 切分
#6.join 字符串拼接(根据’‘内容进行拼接)
print(‘ ‘,join([‘ming‘,‘18‘))
#7.replace 字符串替换
str1=’my name is ming,my age 18!’
print(str1)
str1.replace(‘ming’,‘shuaige‘)
print(str1)
#8.isdigit 判断字符串是否为数字
choice=input(’请选择功能:[0,1,2]‘)
#判断用户选择的是否是数字
print(choice.isdigit())
Python总结1
原文:https://www.cnblogs.com/23123minghihihi/p/11079143.html