Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of basic Technology of Python

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report