Python Foundation _0623

Source: Internet
Author: User

Named rules:

Project name Package name python file name

1. Cannot start with a number, cannot use Chinese

2. Cannot use keywords

3. English Letter Test_06_23

4. Alphanumeric underline (cannot start with a number)

5. See the name of knowing age

Variable:

x = 1 #定义一个变量x, and is assigned a value of 1

Print (x) #如果要引用某个变量 to ensure that the variable has been assigned a defined value

Common data types: shaping floating-point Boolean strings

age = #关键字 int

Score = 99.9 #浮点数 decimal key float

True #关键字 Boolean bool True False

False

String:

Content keyword in pairs of single or paired double quotes: str

Age = ' 20 '

Print (' X ')

Some special uses of strings:

A = ' Hello '

b = ' World '

c = 6

Concatenation of strings ' + ', "+" data types should be the same

String with other data types to do splicing coercion and then use ' + '

Forced conversion str (variable name/variable value)

Print (A+str (c))

', ', using a comma to output the result will be ordered an obvious space, string with other data types to be spliced

The slice value of the string (take left without right)

z = ' Hello '

The index of the string is starting from 0

Single String value: String variable name [index position]

Print (z[1]) E

Multiple string values: string variable name [where the character index begins: where the character index ends +1]

Print (Z[1:4]) ell

The character index ends where +1 has no bounds, so it can cross over

Print (Z[1:10]) Ello

Reverse order:

Print (z[-5:-3]) he

Last value: Print (Z[-1])

Formatted output:

Age = 18

Sex = ' female '

Print (' Lucy is %s years old, ' % of age ')

Print (' Lucy is%s years old, she's a%s ' % (age, Sex))

Print (' Lucy is {} years old '. Format (age))

Print (' Lucy is {0} years old, she's a {1} '. Format (age, Sex)

Placeholder:%s%f%d

Python Foundation _0623

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.