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

Python indented coding + arithmetic operator + method of definition and assignment

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

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "python indented coding + arithmetic operator + method of definition and assignment". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Indented coding

Interpretation type: there is no compilation link, run the execution code directly to show the effect

Indented coding style:

The code block does not use curly braces {} to contain class and function logic judgment code

Logical judgment:

A b='51CTO'f=Trueif 'Hello' FRV cymbprint (c) else:c=a+bprint (c)

The effect is as follows:

2. Arithmetic operator

Features: easy to learn, read, maintain, cross-platform, extensible, etc.

Operator

Serial number

Arithmetic operator

Symbol

one

+

Plus sign

two

-

Minus sign

three

*

Multiply by a sign

four

/

Divide by sign

five

%

Take the mold

six

**

Power, which returns the y power of x

seven

/ /

Rounding down

The code is as follows:

# add, subtract, multiply and divide aq2022-2*16/11print (value of'a:'+ str (a)) # take module b=2022%2c=2022%2000print (value of'b:'+ str (b)) print (value of'c:'+ str (c)) # power of d=2**5print (value of'd:'+ str (d)) print ('2analogy = 2*2*2*2*2:'+str (2' e) # rounding e=23//2print (value of'e:'+ str (e))

The effect is as follows:

Definition and assignment

Object-oriented: programming techniques that support object-oriented style or code encapsulation in objects

Variable definition and assignment

Also use the equal sign = for variable definition and assignment

Variables are created and saved to memory when they are defined and assigned

Method 1. The code is as follows:

# variable definition and assignment method-a = 'Hello' b='51CTO'c=a+bprint (c)

Assignment method 2, the code is as follows:

# variable definition and assignment method 2 d, eMagnedDefinition 'Hello','51 CTO relegated and assigned eprint (f)

The effect is as follows:

This is the end of "python indented coding + arithmetic operators + methods of definition and assignment". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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