用户输入
name = input("please input your name:")
查看变量类型
print type(name)
强制定义变量为整数
age = int(input("pls input your age:"))
去除开头结尾输入的空格
name = input("pls input your name:").strip()
输出
print(name)
格式化输出
zara = ‘abc‘ print(‘you name %s‘ % (zara))
长度
len(name)
isdigit()方法检测字符串是否只由数字组成
#!/usr/bin/python str = "123456"; # Only digit in this string print str.isdigit(); str = "this is string example....wow!!!"; print str.isdigit(); 输出结果 True
输出结果 False
split()方法通过指定分隔符对字符串进行切片
str.split(str="", num=string.count(str))
str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
num -- 分割次数
返回分割后的字符串列表
>>> str = "this is string example....wow!!!" >>> print (str.split()) [‘this‘, ‘is‘, ‘string‘, ‘example....wow!!!‘] >>> print (str.split(‘i‘,1)) [‘th‘, ‘s is string example....wow!!!‘] >>> print (str.split(‘w‘)) [‘this is string example....‘, ‘o‘, ‘!!!‘]
原文:http://www.cnblogs.com/sxlnnnn/p/6362702.html