Python3 basic data type, Python3 Data Type

Source: Internet
Author: User

Python3 basic data type, Python3 Data Type
Variables in Pyhon do not need to be declared. You only need to assign values before use, and the variables are created after being assigned values.

Python variables do not have a type. The type referred to is only the type of objects in the memory.

Python has six standard data types:

  • Numbers (number)
  • String (String)
  • List)
  • Tuple (tuples)
  • Sets)
  • Dictionaries (dictionary)
Numbers (number)

Python 3 supports int, float, bool, and complex (plural) types. It is very intuitive to use, just like writing an article. The use of numbers can be used as calculators, such:

>>> 5 + 4 # Add 9 >>> 4.3-2 # subtract 2.3 >>>> 3*7 # multiply by 21 >>> 2/4 # Except 0.5 >>> 2 // 4 # integer 0 after Division

Note:

  • 1. Python can assign values to multiple variables at the same time, such as a, B = 1, 2.
  • 2. A variable can point to different types of objects by assigning values.
  • 3. Division (/) always returns a floating point number. To obtain an integer, use the // operator.
  • 4. In hybrid computing, Pyhton converts an integer to a floating point number.
String (String)

String 'str' in Python is enclosed by single quotation marks ('') or double quotation marks (" "), and special characters are escaped using a backslash.

>>> S = 'Yes I don \ '# Escape >>> print (s, type (s )) yes I don't <class 'str' >>> print (s, type (s), len (s) Yes I don't <class 'str'> 11

If you want to escape the backslash, you can add an r to the front of the string to indicate the original string. The backslash can be used as a line break to indicate that the previous line is the continuation of the next line.

>>> print('c:\python\bin\local')c:\pythoin\local>>> print(r'c:\python\bin\local')c:\python\bin\local

 

Strings can be connected in series using the + operator, or the * operator is used to repeat:

>>> book = 'python' + 'C++' + 'Perl'>>> print(book)pythonC++Perl>>> s = 'good'*3>>> print(s)goodgoodgood

 

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.