Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-05-31 20:46:53 09月13日 Update

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!

Tags: Code operators operations variables arithmetic coding effects ways hello objects methods content more knowledge logic style learning practicality addition subtraction multiplication and division learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux Redmi Docker NVidia