Python notes One

Source: Internet
Author: User

String learning----------Input Interactive inputs----------
name = input( ‘please enter your name:‘ )print (name)
----------Input Interactive input calculation----------
value1 = 1024 * 512value2 = input(‘num1:‘)value3 = input(‘num2:‘)print (value1)print (value2)print (value3)print (value1 * value2)print (value1 * value3)#当value2 * value3的时候不能如上表示
----------in to determine the string contained in the variable/value----------
s = "Wind and cloud"weather1 = "Wind" in sweather2 = "SB" in sprint (weather1)print (weather2)
----------Variable tuple----------
Wind = "weather1"Paul = "name"Rain = "weather2"_Coll_1 = [‘Wind‘,‘Paul‘,‘Rain‘]print(_Coll_1)_Cont_1 = "Wind" in _Coll_1print (_Cont_1)
----------type to view the class of the object, the generic string is the standard input----------
temp1 = "123"_123_io = type(temp1)print(_123_io)temp2 = "hey"_hey_io = type(temp2)print(_hey_io)
----------The dir view feature----------
temp = "wind"print(dir(temp))
----------Upper lowercase into uppercase----------
temp = "wind"print(temp.upper())
----------count string counts strings that must be within a pair of quotation marks----------
_name_coll = ("paul,vencent,sunny,anny,should,bilibili,david,paul")_coll = _name_coll.count("nn")print(_coll)
----------endswith string tail output definition----------
temp = "hello"print(temp.endswith(‘e‘,0,2))    #字符串的0-2的字符he,是以e结尾,0也可以写成1
----------Center-occupied output----------
a1 = "alex"a2 = a1.center(20,‘*‘)print(a2)#字符总数20个,以alex为中心,两边以*号填充
----------Count statistic Specifies the number of strings----------
a1 = "alex is alpa"a2 = a1.count(‘al‘,5,12)print(a2)
----------Expandtabs Separator Design 20-bit----------
content = "hello\t123"print(content)print(content.expandtabs())print(content.expandtabs(20))
----------Find string bit number lookup
s = "alex hello"print(s.find("h"))print(s.find("p"))#找不到的字符,会显示负数
----------str string standard output, string position output definition
str = ‘Runoob‘print  (str[0:3])print (str[0])print (str[2:5])print (str[2:])print (str * 2)print (str + "TEST")
----------\ n is a newline character, R converts special characters in a string to ordinary characters
print(‘Ru\nnoob‘)print(r‘Ru\nnoob‘)
----------format placeholder substitution, ordered arrangement
x = "hello {0}, age {1}"print(x)y = x.format("paul","27")print(y)
----------Join
alex = "name1"should = "name2"paul = "name3"dio = "name5"name = [alex ,should ,paul ,dio]_name_join = "".join(name)print(_name_join)#将值变成一个整体字符串输出,如果不用元组,只是字符串,可以使用双引号把字符串引起来,加入空格,是字符串相互隔开。name = "alex ","should ","paul ","dio "print (name)_name_join = "".join(name)print(_name_join)
----------Replace replacement string
x = "alex is alex"y = x.replace("al","AA")print(y)
----------Split to slice and separate a string
x = "alex\nalex"y = x.split()print(y)

Python notes One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.