0% found this document useful (0 votes)
4 views1 page

Rules

53ww

Uploaded by

ulugbekuktamgli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Rules

53ww

Uploaded by

ulugbekuktamgli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Naming rules for variables

It should be clear from the name of a variable what data it stores


The name of a variable should not consist of a single letter
The name of a variable must be written in small letters, with underscores between the
words, if necessarry
The variable name should not be the same as the name of commands, such as “print,”
“if,” etc...

Wrong Х
a = 'John'
AGE = 11
DateBirth = 2010

Correct V
name = 'John'
age = 11
date_birth = 2010

When you need to put spaces

Spaces should be placed before and after the following operators: =, ==, <, >, !=, <>, <=,
>=, in, not in, is, is not, and, or, not
Spaces must be placed after commas
There is no need to put spaces between equals in function arguments.

Wrong Х
def eating(fruit):

print(‘Om-Nom-nom’+fruit)

fruit='plum'

fruits=['apple','orange','banana','pineapple']

if fruitinfruits:
eating(fruit = fruit)

Correct V
def eating(fruit):

print(‘Om-Nom-nom’ + fruit)

fruit = 'plum'

fruits = ['apple', 'orange', 'banana', 'pineapple']

if fruit in fruits:
eating(fruit=fruit)

Indent

For a command to be executed inside of for, if, def, и etc., you must add an indent,
before that command, using the Tab key:

if 5 > 3:
print(‘more’)

Wrong Х

spase

Correct V


Tab

Empty lines

Separate functions with two empty lines


Separate classes with two empty lines
You must add two empty lines afte the libraries are connected
Methods (functions) inside the class must be separated by one empty line
Use an empty line to separate code into logical parts.

Wrong Х
import random

class MyClass:

def __init__(self):

self.name = 'My name'

def say_hello(self):

return 'hello world'

def my_func():

i = random.randint(1, 100)

return i

myclass = MyClass()

Correct V

.
.

import random

class MyClass:

def __init__(self):

.
self.name = 'My name'

def say_hello(self):

.
.
return 'hello world'

def my_func():

i = random.randint(1, 100)

.
.

return i

myclass = MyClass()

+7 (958) 580-25-77

You might also like