Enjoy Learning Class-Python Programming Basics_Intefrankly

Enjoy Learning Class-Python Programming Basics

printout

Use of numbers

Use the string

Use List

Using conditional judgments

Using the loop

printout

If we use the command line interactive environment, we can output certain numbers, strings and variables directly, if we need to use the print function in the .py file, e.g.

print('Hello Python')

Use of numbers

Simple numbers contain integers and floating point numbers that can be used to perform some arithmetic operations such as; adding, subtracting, multiplying, dividing, and taking remainders, for example.

a = 200 b = 10 x = a + b print(x) x = a - b print(x) x = a * b print(x) x = a / b print(x) x = a % b print(x)

Use the string

Strings are quoted using single quotes(')、 Or double quotes(") Expanded up character sequences， Indicates the description of a message， for example： name and surname、 Correspondence address, etc.。

s1 = 'Hello world' s2 = "This is a string" print(s1) print(s2) print(s1[0]) # first characterH print(s1[0:3]) # Hel

Use List

A list is a collection of data, similar to an array, that can be accessed by means of subscripts, e.g., a sequence of numbers, a sequence of strings, etc.

l = [1,2,3,4,5] print(l[0])# 1 print(l[1:3]) # [2,3]

Using conditional judgments

Conditional judgments can be made in Python using if elif, etc., for example, to compare the size of two numbers.

a = 1 b = 2 m = 0 if a>b: m = a else: m = b print(m)

Using the loop

Loops can be used to perform some repetitive calculations. Commonly used loops are for loops, while loops, etc., and are often used in conjunction with the range function range().

for x in range(10): print(x) # exports 0 up to9 x = 10 while x>0: print(x) x = x - 1 # exports 10 up to1

Recommended>>
1、Qu Zhou with an Android phone look out someone else can use his phone to steal your money
2、Computer data recovery in five easiest steps
3、The AI technology and principles behind the Google app Guess the Song
4、All the dry information of the forum Wang Chen The Black Forest On the Future of Competition
5、Embark SelfDriving Semi Truck Reaches 2400 Miles in Testing

已推荐到看一看 和朋友分享想法
最多200字，当前共 发送

已发送

确定
分享你的想法...
取消

确定
最多200字，当前共

发送中