Python basics -- statement

	所谓判断就是在程序中满足某些条件,才会做某些事情,不满足则不回去做
  1. Judgment statement
    if Judgment content
    Action to be performed when my condition is met
    Example:
    Judging age, if age is greater than 18, print adult
    age=int(input("Please enter your age"))
    if age > 18:
    print(" adults")insert image description here

  2. If-else uses the format
    if the condition to be judged
    After the condition is met, the thing to be executed, the thing to be executed after the
    else
    condition is not established
    Example:
    Judging the age, if age is greater than or equal to 18, enter adult, otherwise minor
    age =18
    if age>=18 :
    print("Adult")
    insert image description here

insert image description here

  1. if-elif-else
    if condition to be judged: the
    condition meets the code to be executed
    elif the condition to be judged: the
    condition meets the code to be executed
    else:
    the result is executed when none of the above conditions are met
    insert image description here
    insert image description here
    insert image description here
    4.if nested
    if to be judged Condition:
    what to do when the condition is true
    if condition to be judged:
    what to do when the condition is true else: what to do when the condition is not true else: what to do
    when the condition is not true



    insert image description here

  2. Loop statement
    The code that needs to be repeatedly executed many times can be completed in a loop. The
    loop is not necessary, but in order to improve the repetition rate of the code

  3. while loop
    while condition:
    condition is met, need to be executed
    condition is met, need to execute
    ...
    insert image description here

  4. Calculate the sum of even numbers between 1–100 (including 1 and 100)
    insert image description here

  5. while loop nested
    while condition:
    when the condition is true, what to do when the
    condition is true, what to do
    ...
    while condition:
    when the condition is true, what to do when the
    condition is true, what to do
    ...
    insert image description here

  6. Print the formula for the multiplication of ninety-nine
    insert image description here

  7. for loop
    for temporary variable in list or string and other iterable objects:
    the code to execute when the loop meets the condition,
    insert image description here
    print the data from 0 to 9 The
    insert image description here
    function of break: when the condition is met, immediately end the loop where the break is located The
    function of continue: when the condition is met , is used to end this loop, and then execute the next loop
    insert image description here
    insert image description here
    pass.
    Pass does nothing, and is generally used as a placeholder statement.

Guess you like

Origin blog.csdn.net/weixin_44826661/article/details/124017965