python basis (three ways formatted output, basic operators, process control IF is determined, the flow control of the while loop, a for loop flow control purposes)

python basis

Three ways formatted output

A placeholder (old version)

ame = 'jqc'
age = 26
print('my name is %s my age is %d' % (name, age))

my name is jqc my age is 26

% S (for all data types),% d (only for the number types)

Two .format format (chicken, not used)

name = 'jqc'
age = 26
print("Hello, {name}. You are {age}-{age}.".format(age=age, name=name))         

Hello, jqc. You are 26-26.

Three. F-String format (simple, recommended)

name = "jqc"
age = 26
print(f"Hello, {name}. You are {age}.")

Hello, jqc. You are 26.

Uppercase F apply.

name = "jqc"
age = 26
print(F"Hello, {name}. You are {age}.")

Hello, jqc. You are 26.

The basic arithmetic operators

10 is assumed as a variable, the variable b is 20.

An arithmetic operator

II. Comparison Operators

III. Assignment operator

IV. Logical Operators

V. identity operator

and is the difference between ==: is configured to determine whether two variables refer to the same objects (whether in the same memory space), a reference value for determining == variables are equal.

Six .python operator precedence

If there is to be calculated priority parentheses on the line

determining if the flow control

A. Grammar

Single-branch structure

if <条件>:
    <代码块>

Two-branch structure

if <条件>:
    <代码块1>
else:
    <代码块2>

Multi-branch structure

if <条件1>:
    <代码块1>
elif <条件2>:
    <代码块2>
...
else:
    <代码块3>

Two .if nesting

if <条件1>:
    <代码块1>:
    if <条件2>:
        pass

The while loop flow control

Uncontrollable cycle all

while + break

This layer out of circulation, out of the loop

while + continue

Out of this cycle

while + else

Cycle is not terminated before execution break

The for loop flow control

Controllable elements + loop container type String (data types may iteration)

for + break

This layer out of circulation, out of the loop

for + continue

Out of this cycle

for + else

Cycle is not terminated before execution break

Guess you like

Origin www.cnblogs.com/asyouwish/p/11291309.html