Basics of Coding and Python

 coding 

  If you want to use the Python language in the Linux system or the Python2 version, you need to add it at the beginning

#  -*- coding:utf8 -*-

  This statement means that when the machine compiles the program you write, it is compiled in the form of utf-8 encoding.

  If it is not added, when using print to output Chinese, it will be garbled

  The specific reason depends on the knowledge of coding:

  Because the computer can only recognize two numbers 0 and 1, the characters that the computer needs to store are composed of a large number of numbers composed of 0 and 1. The first rule for storing these numbers was the Ascill code.

  But the capacity of ASCII code compilation can only be 8 bits, and then people invented Unicode. It can compile 16 bits, which means it can store more different combinations of 0s and 1s, which means it can compile more characters. But here comes the problem, assuming that the ASCIIl code of the character a is 00000001, If it is Unicode compilation, the Unicode code of a is 000000000000001. See, there are so many 0s, don't count them, it is estimated that you will be dizzy when you count! , So many 0's might as well use ASCII code to compile, and super waste of memory!

  From this, people invented the uft-8 encoding, which can store at least 8 bits of 0 and 1, at least! ! ! ! That is to say, when he stores a, the compilation is 00000001. He can store up to 4 bytes of characters, one character, and 8 bits, which means that he can store up to 32 bits. When he stores Chinese, he will automatically Extended 16-bit 24-bit 32-bit, which saves a lot of memory space.

 The power of Python

  To see how powerful python is, I can only say that hahaha python is the best language ever! I must learn python! Because it is so convenient!

n = input ('Are you a member of the first club')
if n == 'yes'
    print('Welcome')'

  As in the above example, input(''string'), input will first output the string in '', and then store the data entered by the user into the variable n.

  Let's take a look at the if statement python's if statement can also determine whether the strings are equal.

 Python basic data types focus

  n = 4**4 #Calculate 4 to the 4th power

  n = 39/4 # Calculate the quotient of 39 divided by 4 with decimals

  n =394//4 #Calculate the quotient of 39 divided by 4 without decimals

 IF与while

  Learned python's if statement condition and loop today

  The format of if is

  if condition:

    statement

  else:

    statement

  Yayu

  if condition:

    statement

  elif condition:

     statement

if 1==1:
    pass
else:
    print(‘sb’)

  If the above statement does not want to perform any operation when 1=1, use pass.

  whlie loop

  To accumulate 1 to 100, we need to use a loop. Since we only learned while today, let's talk about the practice of wihile

a = 1
b = 0
while a<101:
    b =  b + a
    a =  a +1
print(b)

  When writing whlie, the condition is true to loop, and false to exit the loop. For this cumulative problem, we need to calculate the number of loops from 1 to 100, and we need to loop 100 times. Do you still remember the gluttonous snake you played with when you were a child, hehe! I think the first gluttonous snake is getting longer and longer (bigger) when accumulating. Since there is food a, then there must be a gluttonous snake b, which is the variable b. Let him eat a in each loop condition. Accumulates again and again, and a is also accumulating, and exits if the loop condition is not reached.

 

The first day is over here, I hope I can continue to study, woo woo ~ Although I missed a lot of courses in school, I hope I can make up for it.

Hope you can learn something!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324623236&siteId=291194637