>>> sr="Discover Python"
>>> type(sr)
<type 'str'>
>>> sr='Discover Python'
>>> type(sr)
<type 'str'>
>>> sr="Discover Python: It's Wonderful!"
>>> sr='Discover Python"
File "<stdin>", line 1
sr='Discover Python"
^
SyntaxError: EOL while scanning single-quoted string
>>> sr="Discover Python: \
... It's Wonderful!"
>>> print sr
Discover Python: It's Wonderful!
>>> passage = 'When using the Python programming language, one must proceed \ ... with caution. This is because Python is so easy to use and can be so \ ... much fun. Failure to follow this warning may lead to shouts of \ ... "WooHoo" or "Yowza".' >>> print passage When using the Python programming language, one must proceed with caution. This is because Python is so easy to use, and can be so much fun. Failure to follow this warning may lead to shouts of "WooHoo" or "Yowza".
>>> passage='\tWhen using the Python programming language, one must proceed\n\
... \twith caution. This is because Python is so easy to use, and\n\
... \tcan be so much fun. Failure to follow this warning may lead\n\
... \tto shouts of "WooHoo" or "Yowza".'
>>> print passage
When using the Python programming language, one must proceed
with caution. This is because Python is so easy to use, and
can be so much fun. Failure to follow this warning may lead
to shouts of "WooHoo" or "Yowza".
>>> passage=r'\tWhen using the Python programming language, one must proceed\n\
... \twith caution. This is because Python is so easy to use, and\n\
... \tcan be so much fun. Failure to follow this warning may lead\n\
... \tto shouts of "WooHoo" or "Yowza".'
>>> print passage
\tWhen using the Python programming language, one must proceed\n\
\twith caution. This is because Python is so easy to use, and\n\
\tcan be so much fun. Failure to follow this warning may lead\n\
\tto shouts of "WooHoo" or "Yowza".
>>> passage = """
... When using the Python programming language, one must proceed
... with caution. This is because Python is so easy to use, and
... can be so much fun. Failure to follow this warning may lead
... to shouts of "WooHoo" or "Yowza".
... """
>>> print passage
When using the Python programming language, one must proceed
with caution. This is because Python is so easy to use, and
can be so much fun. Failure to follow this warning may lead
to shouts of "WooHoo" or "Yowza".
>>> help(str)
Help on class str in module __builtin__:
class str(basestring)
| str(object) -> string
|
| Return a nice string representation of the object.
| If the argument is a string, the return value is the same object.
|
| Method resolution order:
| str
| basestring
| object
|
| Methods defined here:
|
| __add__(...)
| x.__add__(y) <==> x+y
|
...
>>> str("Discover python")
'Discover python'
>>> str(12345)
'12345'
>>> str(123.45)
'123.45'
>>> "Wow," + " that " + "was awesome."
'Wow, that was awesome.'
>>> "Wow,"" that ""was Awesome"
'Wow, that was Awesome'
>>> "Wow! "*5
'Wow! Wow! Wow! Wow! Wow! '
>>> sr = str("Hello ")
>>> id(sr)
5560608
>>> sr += "World"
>>> sr
'Hello World'
>>> id(sr)
3708752
>>> sr = "Discover Python!"
>>> sr.upper()
'DISCOVER PYTHON!'
>>> sr.lower()
'discover python!'
>>> sr = "This is a test!"
>>> sr.split()
['This', 'is', 'a', 'test!']
>>> sr = '0:1:2:3:4:5:6:7:8:9'
>>> sr.split(':')
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>>> sr=":"
>>> tp = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
>>> sr.join(tp)
'0:1:2:3:4:5:6:7:8:9'
>>> sr="0123456789" >>> sr[0] '0' >>> sr[1] + sr[0] '10' >>> sr[4:8] # Give me elements four through seven, inclusive '4567' >>> sr[:-1] # Give me all elements but the last one '012345678' >>> sr[1:12] # Slice more than you can chew, no problem '123456789' >>> sr[:-20] # Go before the start? '' >>> sr[12:] # Go past the end? '' >>> sr[0] + sr[1:5] + sr[5:9] + sr[9] '0123456789' >>> sr[10] Traceback (most recent call last): File "<stdin>", line 1, in ? IndexError: string index out of range >>> len(sr) # Sequences have common methods, like get my length 10
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有