Article From:

mainly for calculation

    1.2 Boolean value bool: Boolean values are two (True True 1,False False 0)It is to judge whether the reaction conditions are correct or not.

    1.3 String STR: in popular terms, quotes are cited as content: a = ‘content

  2. Formatted output

    Now there is a need to ask the user’s name, age, work, hobbies, and then print the following format.

------------ info of Alex Li -----------
Name : Alex Li
Age : 22
job : Teacher
Hobbie: girl
------------- end -----------------

 There are two ways:

The first is placeholder,%% placeholder [%s: string form] [%d: digital form].

You just have to prepare the format that you need to print first, because the information inside is required by the user, so you can’t predict it, so you can put a placeholder in the position first and then map the placeholder in the string to the external variable.

mingpian = '''
------------ info of %s -----------
Name : %s
Age : %d
job : %s
Hobbie: %s
------------- end -----------------
'''%( 'Zhang Shuai','Zhang Shuai',56,'Migrant workers','money')         #Add the information you need in it  ***There are several unknowns to fill in a few informationprint(mingpian)


name = input('Full name')
age = int(input('Age'))
job = input('work')
Hobbie = input('hobby')
info = '''
------------ info of %s -----------
Name : %s
Age : %s
job : %s
Hobbie: %s
------------- end -----------------
''' %(name , name , age , job , Hobbie)    #The% of this line is to associate the preceding string with variables after parenthesis.
                                        # The first row of%s is a placeholder, which represents name.
 #The three quotes are very powerful and can represent annotations, if there is a "info" in front of the text, and the text of a line is not annotated in such a text.

View Code

###In addition to%s representing string placeholders and%d, he is a digit placeholder. If you replace%d above age, it means you can only enter numbers.

###  input  All input received is default to string format, and it wants to be converted to digits, which can be age = int (input (“age”)).

msg = "I'm%s, age%d, and my current study is 80%"

%('Jin Xin',18)

###Note that% 80% is not placeholder, so how do I explain to the Python interpreter that this is a simple% instead of placeholder?

     Answer: add one more percent after 80%: 80%%

The second method: using a dictionary (DIC)

dic(Dictionaries = {'name':'Old boy', 'age':56, 'job':'Boss','hobbie':'money'}
mingpian = '''
------------ info of %(name)s -----------
Name : %(name)s
Age : %(age)d
job : %(job)s
Hobbie: %(hobbie)s
------------- end -----------------

The result is------------ info of The old boy - -- - ----
Name : Old boyAge:56
job : BossHobbie: money------------- end -----------------


  3.Basic operator

    3.1 Arithmetic operation

Set: a = 10, B = 20


    3.2Comparison operation

Set: a = 10, B = 20


An equal sign “=” is an assignment; the two equal sign “= =” is a comparison.


      3.3.1 logical operator

1″ is the first case: logical operators are all comparative operations.
> 2; second cases, logical operators are numbers before and after.
Or 1 to 1, and 0 to 0
int—> bool is zero for True, else is False.



          bool(0) You’ll get Falsefalse


  And conclude that:Or 1 to 1, and 0 to 0(The meaning of “1” and “0” is true and false here.

3.3.3″ number and transformation of bool value.

 Digital conversion to boolNon zero is true

                   bool DigitsIt’s really 1 True for 0 False



 4.ascii  unicode  gbk

Every computer has a password book【Cipher: a comparison table between binary and character

At the beginning of the birth of the computerascii (The primary cipher book contains contents: special characters, numbers, letters. It

  0000 0001  8Bit = = = 1 bytes, 1 bytes, representing a character.

    【8The first position in the position is the reserved position, all are 0]

  Character: the smallest element that makes up the content.

    For example, ASD: “a” “B” “C” is the sameThe smallest unit of “ABC”

       China: the word “Zhong” or “Guo” is the smallest unit of “China”.

Wanguo Code:unicode

    At the beginning of the creation, 16 bits, or two bytes, represent one character.

      a : 0000 0000 0000 0001

      Middle: 0110100000100000

    Upgrade: 32 bits, or four bytes, represent one character

      a : 0000 0000 0000 0000 0000 0000 0000 0001

      Middle: 1010100010101010 1111000000001001

      This will cause a waste of resources

Upgrade to unicode: UTF-8.

    utf-8:At least one character is represented in 8 digits

       a:0000 0001 (The alphabet is expressed in 1 bytes.

       European Text: 0000000000000001 (expressed in two characters)

       Asian characters (middle): 0000000000000000 00000001 (expressed in three characters)

China improves on Unicode: GBK (national standard) has nothing to do with UTF-8.

           a :0000 0001 (The alphabet is expressed in one byte.

        Medium: 0000000000000001 (expressed in two characters)


8 Bit (bit) = 1 bytes (byte)

1024 byte = 1 KB

1024 KB = 1 MB

1024 MB = 1 GB

1024 GB = 1TB


Link of this Article: 18/04/27 basic data type

Leave a Reply

Your email address will not be published. Required fields are marked *