Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of basic Technology of Python

Shulou Source: shulou.com Published: 2022-06-02 12:10:44 10月27日 Update

This article mainly explains the "Python basic technology example analysis", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python basic technology example analysis" bar!

Foundation 1. Variable

You can simply think of a variable as a word that stores values.

Be reasonable, there is no need to explain what the variable is. Everybody knows.

In Python, defining variables and assigning values to variables is very simple. For example, if you want to store the number 1 in a variable called one, then all you need to do is:

One = 1

Isn't it very simple? As an example, you can play it freely, like below, assign 2 to two and 10000 to some_number:

Two = 2

Some_number = 10000

Of course, in addition to integers, we can also set Boolean types, strings, single precision, and some other data types. As follows:

# booleans

True_boolean = True

False_boolean = False

# string

My_name = "Leandro Tk"

# float

Book_price = 15.802. Flow control: branch statement

If, this statement is used to determine whether the condition is met, followed by a logical expression whose final value is True or False, and if true, executes the statement in if. As follows:

If True:

Print ("Hello Python If")

If 2 > 1:

Print ("2 is greater than 1")

Because 2 is greater than 1 and the condition is true, the print statement is executed

Of course, if the conditions are not met, then else will come in handy!

If the final value of the logical expression followed by if is false, the program in else will be run as follows:

If 1 > 2:

Print ("1 is greater than 2")

Else:

Print ("1 is not greater than 2")

You can also use elif, which is an abbreviation for else if, but don't make any mistakes.

If 1 > 2:

Print ("1 is greater than 2")

Elif 2 > 1:

Print ("1 is not greater than 2")

Else:

Print ("1 is equal to 2") 3. Loop / iterator

In Python, we have a variety of iterations, and I'll talk about two here:

While loop: when the logical expression is true, the block of code indented under while will be executed in a loop. So the following code snippet will print from 1 to 10.

Num = 1

While num

Tags: Methods variables objects loops properties data instances types behaviors storage integers foundations data structures conditions structures learning code examples parameters that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB Shulou Tech Info Linux Microsoft