Hướng dẫn explain the general structure of python program and give example - giải thích cấu trúc chung của chương trình python và cho ví dụ

Trong bài viết này, bạn sẽ biết về cấu trúc đúng và định dạng các chương trình Python của bạn.

Các câu lệnh Python Nói chung, trình thông dịch đọc và thực thi các câu lệnh theo từng dòng i.e theo tuần tự. Mặc dù vậy, có một số tuyên bố có thể thay đổi hành vi này như tuyên bố có điều kiện. & NBSP; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Hầu hết, các câu lệnh Python được viết theo định dạng như vậy mà một câu lệnh chỉ được viết trong một dòng. Trình thông dịch coi ký tự dòng mới là người kết thúc của một hướng dẫn. Nhưng, viết nhiều câu lệnh cho mỗi dòng cũng có thể tìm thấy bên dưới.Examples: In general, the interpreter reads and executes the statements line by line i.e sequentially. Though, there are some statements that can alter this behavior like conditional statements.
            Mostly, python statements are written in such a format that one statement is only written in a single line. The interpreter considers the ‘new line character’ as the terminator of one instruction. But, writing multiple statements per line is also possible that you can find below.
Examples:

print['Welcome to Geeks for Geeks'

Output:

Welcome to Geeks for Geeks

x

# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
0
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
1
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
2
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
3
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
4
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
3
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
6
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
3
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
8
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
9

print

[[1, 2, 3], [3, 4, 5], [5, 6, 7]]
1
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
2
[[1, 2, 3], [3, 4, 5], [5, 6, 7]]
3
# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']
6
[[1, 2, 3], [3, 4, 5], [5, 6, 7]]
5

Nhiều câu lệnh cho mỗi dòng chúng ta cũng có thể viết nhiều câu lệnh cho mỗi dòng, nhưng nó không phải là một thông lệ tốt vì nó làm giảm khả năng đọc của mã. Cố gắng tránh viết nhiều câu trong một dòng. Tuy nhiên, bạn vẫn có thể viết nhiều dòng bằng cách chấm dứt một câu lệnh với sự trợ giúp của ‘; ; & nbsp; & nbsp; & nbsp; Ví dụ, hãy xem xét các mã sau. We can also write multiple statements per line, but it is not a good practice as it reduces the readability of the code. Try to avoid writing multiple statements in a single line. But, still you can write multiple lines by terminating one statement with the help of ‘;’. ‘;’ is used as the terminator of one statement in this case.
        For Example, consider the following code.

print

2 Persons should have ID Cards
8print
x > 5
x > 5
x > 5
x < 5
x < 5
0print
x > 5
x > 5
x > 5
x < 5
x < 5
2

Tiếp tục dòng để tránh các câu lệnh ScrollingSome trái và phải có thể trở nên rất dài và có thể buộc bạn phải cuộn màn hình bên trái và phải thường xuyên. Bạn có thể phù hợp với mã của mình theo cách mà bạn không phải cuộn ở đây và ở đó. Python cho phép bạn viết một câu lệnh duy nhất trong nhiều dòng, còn được gọi là tiếp tục dòng. Tiếp tục dòng tăng cường khả năng đọc là tốt.
Some statements may become very long and may force you to scroll the screen left and right frequently. You can fit your code in such a way that you do not have to scroll here and there. Python allows you to write a single statement in multiple lines, also known as line continuation. Line continuation enhances readability as well.

# Bad Practice as width of this code is too much.
 
#code
x = 10
y = 20
z = 30
no_of_teachers = x
no_of_male_students = y
no_of_female_students = z
 
if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
    print['The course is valid']
 
# This could be done instead:
 
if [no_of_teachers == 10 and no_of_female_students == 30
    and no_of_male_students == 20 and x + y == 30]:
    print['The course is valid']

Các loại tiếp tục dòng chung, có hai loại tiếp tục dòng
In general, there are two types of line continuation

  • Tiếp tục dòng ẩn Đây là kỹ thuật đơn giản nhất trong việc viết một câu nói trải rộng nhiều dòng. Bất kỳ câu lệnh nào chứa dấu ngoặc đơn ['['], dấu ngoặc ['['] hoặc niềng răng xoăn ['{'] được cho là không đầy đủ cho đến khi tất cả Phù hợp với dấu ngoặc đơn, dấu ngoặc vuông và niềng răng xoăn đã gặp phải. Cho đến lúc đó, câu lệnh có thể được tiếp tục ngầm trên các dòng mà không gây ra lỗi.
    This is the most straightforward technique in writing a statement that spans multiple lines.
    Any statement containing opening parentheses [‘[‘], brackets [‘[‘], or curly braces [‘{‘] is presumed to be incomplete until all matching parentheses, square brackets, and curly braces have been encountered. Until then, the statement can be implicitly continued across lines without raising an error.
    Examples:

    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    1

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    1
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    2
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    4
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    6print3

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    1
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    8
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3[0print3

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    1[0
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3[6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3[8
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    9

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    9

    print'Welcome to Geeks for Geeks'3

    Output:

    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    

    'Welcome to Geeks for Geeks'4

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0 'Welcome to Geeks for Geeks'6

    'Welcome to Geeks for Geeks'7

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0
    2 Persons should have ID Cards
    
    1

    0

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0 2

    3 [

    56____10 'Welcome to Geeks for Geeks'6 9

    5x 1

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0 'Welcome to Geeks for Geeks'6 9

    5x 6'Welcome to Geeks for Geeks'6

    5x 9

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6print[
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    03
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    04

    Output:

    2 Persons should have ID Cards
    

  • Tham gia dòng tiếp tục dòng rõ ràng được sử dụng chủ yếu khi không áp dụng dòng dòng ẩn. Trong phương pháp này, bạn phải sử dụng một ký tự giúp thông dịch viên hiểu rằng câu lệnh cụ thể đang kéo dài nhiều hơn một dòng. & NBSP; & nbsp; & nbsp; & nbsp; Backslash [\] được sử dụng để chỉ ra rằng một câu lệnh kéo dài nhiều hơn một dòng. Vấn đề là cần lưu ý rằng, phải là nhân vật cuối cùng trong dòng đó, ngay cả không gian trắng không được phép. Xem ví dụ sau để làm rõ
    Explicit Line joining is used mostly when implicit line joining is not applicable. In this method, you have to use a character that helps the interpreter to understand that the particular statement is spanning more than one lines.
            Backslash [\] is used to indicate that a statement spans more than one line. The point is to be noted that ” must be the last character in that line, even white-space is not allowed.
    See the following example for clarification

    x ____10

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    07

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    2
    2 Persons should have ID Cards
    
    5
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    4
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    07

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6
    2 Persons should have ID Cards
    
    5 [0
    2 Persons should have ID Cards
    
    5 [6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    07

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    
    6
    2 Persons should have ID Cards
    
    5
    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    8

    print

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    23

  • Nhận xét trong các bình luận của PythonWriting trong mã là rất quan trọng và chúng giúp có thể đọc được mã và cũng nói thêm về mã. Nó giúp bạn viết chi tiết chống lại một tuyên bố hoặc một đoạn mã. Thông dịch viên bỏ qua các ý kiến ​​và không đếm chúng trong các lệnh. Trong phần này, chúng tôi sẽ học cách viết bình luận bằng Python. & NBSP; & nbsp; & nbsp; & nbsp; Các biểu tượng được sử dụng cho các nhận xét viết bao gồm băm [#] hoặc dấu ngoặc kép ba dấu ngoặc kép [Hồi giáo]. Hash được sử dụng để viết các bình luận dòng đơn không kéo dài nhiều dòng. Dấu ba trích dẫn được sử dụng để viết nhiều bình luận dòng. Ba dấu ngoặc kép ba dấu ngoặc kép để bắt đầu nhận xét và một lần nữa ba dấu ngoặc kép để kết thúc nhận xét.
    Writing comments in the code are very important and they help in code readability and also tell more about the code. It helps you to write details against a statement or a chunk of code. Interpreter ignores the comments and does not count them in commands. In this section, we’ll learn how to write comments in Python.
            Symbols used for writing comments include Hash [#] or Triple Double Quotation marks[“””]. Hash is used in writing single line comments that do not span multiple lines. Triple Quotation Marks are used to write multiple line comments. Three triple quotation marks to start the comment and again three quotation marks to end the comment.
    Consider the following examples:

    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    26

    print'Welcome to Geeks for Geeks'3

    Lưu ý Lưu ý rằng băm [#] bên trong một chuỗi không đưa ra nhận xét. Hãy xem xét các ví dụ sau đây để trình diễn. Do note that Hash [#] inside a string does not make it a comment. Consider the following example for demonstration.

    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    31

    print

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    33

    White Spacesthe Các ký tự khoảng trắng phổ biến nhất là như sau:
    The most common whitespace characters are the following:

    Tính cáchMã ASCIIBiểu hiện theo nghĩa đen
    Không gian32 [0x20]‘& Nbsp;‘
    chuyển hướng9 [0x9]\ T…
    dòng mới10 [0xa]'\N'

    * Bạn luôn có thể tham khảo bảng ASCII bằng cách nhấp vào đây. Không gian chuyển đổi hầu hết bị bỏ qua và hầu hết không được yêu cầu, bởi trình thông dịch Python. Khi rõ ràng nơi một mã thông báo kết thúc và cái tiếp theo bắt đầu, khoảng trắng có thể được bỏ qua. Đây thường là trường hợp khi các ký tự không phải là đồngumeric đặc biệt có liên quan.Examples:

    Whitespace is mostly ignored, and mostly not required, by the Python interpreter. When it is clear where one token ends and the next one starts, whitespace can be omitted. This is usually the case when special non-alphanumeric characters are involved.
    Examples:

    x ____10

    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    8

    Các

    print

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    49

    Không gian trắng là cần thiết trong việc tách các từ khóa với các biến hoặc các từ khóa khác. Xem xét các ví dụ sau.

    x

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    1
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    2
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    4
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    3
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    9

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    59____10
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    4

    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    6
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    0
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    59
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    65
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    66

    print'Welcome to Geeks for Geeks'3

    Không gian trắng như Cú pháp thụt đầu vào là khá dễ dàng, nhưng bạn vẫn phải quan tâm đến việc viết mã. Thắng được sử dụng để viết mã python. & Nbsp; & nbsp; & nbsp; & nbsp; Không gian trắng trước khi một tuyên bố có vai trò quan trọng và được sử dụng trong thụt lề. Whitespace trước một tuyên bố có thể có một ý nghĩa khác. Hãy để thử một ví dụ.
    Python’s syntax is quite easy, but still you have to take some care in writing the code. Indentation is used in writing python codes.
            Whitespaces before a statement have significant role and are used in indentation. Whitespace before a statement can have a different meaning. Let’s try an example.

    print[

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    71
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    72

    5print[

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    71
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    72

    Không gian trắng hàng đầu được sử dụng để xác định nhóm các câu lệnh như trong các vòng lặp hoặc cấu trúc điều khiển, v.v.
    Example:

    x ____10

    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    8

    Các

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    863
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    88[0
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    90

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    91print[
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    94
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    95

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    86
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    97
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    98

    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    91print[
    [[1, 2, 3], [3, 4, 5], [5, 6, 7]]
    
    02
    # Bad Practice as width of this code is too much.
     
    #code
    x = 10
    y = 20
    z = 30
    no_of_teachers = x
    no_of_male_students = y
    no_of_female_students = z
     
    if [no_of_teachers == 10 and no_of_female_students == 30 and no_of_male_students == 20 and [x + y] == 30]:
        print['The course is valid']
     
    # This could be done instead:
     
    if [no_of_teachers == 10 and no_of_female_students == 30
        and no_of_male_students == 20 and x + y == 30]:
        print['The course is valid']
    72

    Không gian trắng là cần thiết trong việc tách các từ khóa với các biến hoặc các từ khóa khác. Xem xét các ví dụ sau.

    Output:

    x > 5
    x > 5
    x > 5
    x < 5
    x < 5
    


Cấu trúc chung của Python là gì?

Các cấu trúc dữ liệu Python cơ bản trong Python bao gồm danh sách, bộ, bộ dữ liệu và từ điển. Mỗi cấu trúc dữ liệu là duy nhất theo cách riêng của nó. Cấu trúc dữ liệu là các container của người Viking, tổ chức và nhóm dữ liệu theo loại. Các cấu trúc dữ liệu khác nhau dựa trên khả năng đột biến và trật tự.list, set, tuples, and dictionary. Each of the data structures is unique in its own way. Data structures are “containers” that organize and group data according to type. The data structures differ based on mutability and order.

Cấu trúc dữ liệu trong Python với ví dụ là gì?

Cấu trúc dữ liệu là tập hợp các yếu tố dữ liệu tạo ra một cách lưu trữ và tổ chức dữ liệu trong máy tính để có thể sử dụng tốt.Ví dụ: các cấu trúc dữ liệu như ngăn xếp, hàng đợi, danh sách được liên kết, v.v.the set of data elements that produce a well-organized way of storing and organizing the data in the computer so it can be used well. For example, the data structures like Stack, Queue, Linked List, etc.

Lập trình Python nói chung là gì?

Python là một ngôn ngữ lập trình được giải thích, tương tác, hướng đối tượng.Nó kết hợp các mô -đun, ngoại lệ, gõ động, các loại dữ liệu động ở mức rất cao và các lớp.Nó hỗ trợ nhiều mô hình lập trình ngoài lập trình hướng đối tượng, chẳng hạn như lập trình thủ tục và chức năng.an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. It supports multiple programming paradigms beyond object-oriented programming, such as procedural and functional programming.

Cấu trúc chung hoặc định dạng chung hoặc cú pháp trong Python là gì?

Cú pháp của ngôn ngữ lập trình Python là tập hợp các quy tắc xác định cách viết chương trình Python.Cấu trúc dòng Python: Một chương trình Python được chia thành một số dòng logic và mọi dòng logic đều bị chấm dứt bởi dòng mới.Một dòng logic được tạo từ một hoặc nhiều dòng vật lý.the set of rules which defines how a Python program will be written. Python Line Structure: A Python program is divided into a number of logical lines and every logical line is terminated by the token NEWLINE. A logical line is created from one or more physical lines.

Bài Viết Liên Quan

Chủ Đề