Beginner Python (ii)

Source: Internet
Author: User

V. Variables and Assignments

A variable in Python does not need to specify its type when declaring it, and it automatically determines the value based on your assignment.

For the assignment of a value type such as a number and a character, the variable is simply a reference to it and cannot be deleted directly (in fact, because of the garbage collection mechanism in Python, you can't really delete anything, and Python automatically judges it "no one" to delete it)

>>> a = 1>>> B = aprint(A, b)print(A, b)9 1

Vi. numbers

int: Signed integer (if out of range is automatically converted to a long integer)

A long integer (whose range depends on the user's virtual memory)

float: floating point

Complex: Complex numbers (imaginary numbers are denoted by the letter J at the end of the number)

BOOL: Boolean value (1 for true,0 represents false,true+false result of 1)

Seven, string

Strings can be defined using a pair of single quotes, double quotes, or three quotation marks;

The string is a sequence of characters, you can use the slice operation of the list to get the substring of the string, or you can use the subscript index to get the position of the characters, the first character subscript is 0, the last character subscript is (-1);

You can use the "+" sign to concatenate two strings (it will re-open a space in memory, create a new string to represent the result of the connection), you can use "*" to specify the number of repetitions of the string.

>>> 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'

Beginner Python (ii)

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.