Python day5 (20170224) __python

Source: Internet
Author: User
1)-connector +, for string links, when the definition str= "ABCD", the definition str2= "12345", Str3=str1+str2,print STR3, the result is abcd12345.
2 Len Method, the Len method can be used to calculate the length of the string, such as Len (STR3) =9.
3) * method, used in string, such as Str= ' abc ', will str1*2 result should be ' abcabc ', such as #*20 operation.
4 in method, indicating whether a character is included in the string, such as: ' G ' in (STR1) returns the result should be false. Note that you must enclose quotes, or you will be given an error. A in a=100 is a variable, and ' A ' is a string.
5 Max and Min methods to determine the maximum and minimum values in the string, a1= ' 12345 ', Max (A1) =5,min (A1) =1.a2= ' ABCD ', max (a2) = ' d ', min (a2) = ' a '.
6 CMP method, comparing two string sizes, the format is CMP (A,B), A>b is 1,a<b, then -1,a=b 0, for example: str1= ' 12345 ', str2= ' ABCDE ', CMP (STR1,STR2) =- 1, indicating that str1 is smaller than str2; similarly, cmp (STR2,STR1) = 1, when the same, the value is 0.
7) Tuples: Tuples can store a series of data, the data types can be different, and the way to use slices to obtain, in parentheses, such as data (' Paul ', ' Male '), get the first element of the tuple, data[0]= Paul. When you define 1 elements, you also save the ', ' number in parentheses, such as data1= (1,), which uses type to view the data type as Tuple,type, or =tuple, as data1= (1), and the type of data1 is int.
8) Tuple assignment: The elements in the tuple, can not be modified by slicing, if you want to modify, you need the entire tuple content to be assigned again, such as: usr= (' Ben ', ', ' Male '), usr[1]=30, the system will error, can be assigned, usr= (' Emily ', 25,female).
9 The content of the tuple, NAME,AGE,SEX=USR, output name,age,sex content, can obtain Ben,20,male data values, its form with nam,age,sex= (' Ben ', 20,male) way, When assigning values to the data in a tuple, the contents of the tuple must be consistent before and after, and the data in parentheses should be quoted in quotation marks, such as a,b,c,d= (E,f,g,h), a,b,c,d= (' e ', ' f ', ' G '), a,b,c= (' A ', ' B ') are all errors.

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: 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.