python--Data types

Source: Internet
Author: User
Tags string methods

Standard data types

Number

Ten21.66= false;print (type (Boolvar));

Type () types detection

Isinstance () type match

Modify the above code

intintbool));

String

str ="Hello Jiao"; # start at index 0 to indexBefore =-1 (contains index=0 does not contain index=-1"Index=-1 is the last character of the string ") print (str[0: -1]); # Hello jia# starting from index 0 to indexBefore =4 (contains index=0 does not contain index=4) print (str[0:4]); # hell# start from index 6 to end (contains index=6) print (str[6: ]); # jiao# output two times string print (str*2); # string concatenation print (str[0:5] +"World !!!");

The string hollow lattice is not omitted.

Escape character Valid

The string method will only return the modified string, the original string variable will not be changed (that is, you cannot modify a character in the string, error)

Lists List

List1 = ["Tom","Jimy",890,22.1,"haha"];p rint (list1);p rint (Type (list1));p rint (list1[0]);p rint (list1[0: -1]);p rint (List1*3); List2= ["Hello Jiao"];listall= List1 +list2;# Delete list element listall[1:2] =[];p rint (listall);

List methods and string methods are broadly consistent, note that the deletion of list elements must be written

list[n:n+1] = [];

It's not possible to write anything else. You might replace this element with a list, an empty string. Because: the elements in the list can be modified.

Tuple tuples

Tuples are similar to lists, declaring lists with [], declaring tuples with ()

Immutable elements in a tuple cannot be modified.

The above sentence is a bit around, for example:

TU1 = ("fftu", ["jiao " ]); tu1[-1[0"fftu";p rint (TU1);

The last element in the tuple is a list that can be modified, even as an element of a tuple.

However, if you modify other elements, you will get an error.

In Python, a variable is not declared, and an object is created when the value is assigned.

To delete an object reference

Del Num1, num2;

python--Data types

Related Article

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.