Python Basic data type

Source: Internet
Author: User

Variables in Python do not need to be declared. Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned.

In Python, a variable is a variable, a memory address pointer, which has no type, and what we call "type" is the type of object in memory that the variable refers to. Similar to other reference types in Java, C.

There are six standard data types in the Python3:

Strings (String)
Boolean Type (Boolean)
Integers (integer)
Floating point (float)
Number (Digit)
Listing (list)
Tuple (tuple)
Collection (sets)
Dictionary (Dictionary)
Dates (date)

One, string

The string str in Python is enclosed in single quotation marks (') or double quotation marks (""), and the special characters are escaped with a backslash (\).

' Yes, he doesn\ ' t ' Print (S, type (s), Len (s)) Yes, he doesn '  'str'>

If you do not want \ To escape, you can precede the string with R or R to indicate the original string:

Print ('C:\some\name') C:\someame Print (R'C:\some\name') C:\some\name

In addition, \ can be used as the red continuation character, indicating that the next line is also the continuation of the previous line. You can also use the "..." or "" ... "" "across multiple lines.

Strings can be concatenated with the + runner or repeated with the * operator:

Note: The use of formatted strings is recommended when the + connection string is not efficient when you re-open memory each time a connection is over and the connection is too high.

>>> S1 ='We'>>> s2 =' is'>>> s3 ='Go'>>>Print(S1 +' '+ s2 +' '+S3) We Are Go>>>>>>Print("%s %s%s"%(S1, S2, S3)) We Are Go>>>>>>Print('Str'+'ing','*'*10) String**********

Python Basic data type

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.