Python beginners (2)

Source: Internet
Author: User

Python beginners (2)

V. Variables and assignments

When declaring a variable in Python, you do not need to specify its type. It is automatically determined based on your value assignment.

For values such as numbers and characters, variables only reference them and cannot directly delete their values. (In fact, due to the garbage collection mechanism in Python, you cannot really delete anything, python automatically determines if it is "nobody" before deleting it)

>>> a = 1>>> b = a>>> print(a, b)1 1>>> a = 9>>> print(a, b)9 1

6. Numbers

Int: signed integer (if the range is exceeded, it is automatically converted to a long integer)

Long: A long integer (its range depends on the user's virtual memory)

Float: Floating Point Number

Complex: plural (the imaginary number is represented by a letter j at the end of the number)

Bool: Boolean value (1 indicates True, 0 indicates False, and True + False indicates 1)

VII. String

A string can be defined by a pair of single, double, or triple quotes;

A string is a character sequence. You can use the list slicing operation to obtain the substring of a string. You can also use the subscript index to obtain the position of the character in the string. The subscript of the first character is 0, the subscript of the last character is (-1 );

You can use "+" to connect two strings (a new space will be created in the memory and a new string will be created to represent the connection result ), you can use "*" to specify the number of string repetitions.

>>> py = 'Python'>>> py[-1],py[0]('n', 'P')>>> py[1:-2], py[:], py[2:], py[:3]('yth', 'Python', 'thon', 'Pyt')>>> he = 'Hello'>>> he+py'HelloPython'>>> py*3'PythonPythonPython'

 

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.