Python3 Data Type _1

Source: Internet
Author: User
Tags null null

Coding

By default, Python 3 source files are encoded in UTF-8, and all strings are Unicode strings. Of course you can also specify a different encoding for the source file:

1 #_*_ coding:utf-8 _*

In Python3, non--ascii identifiers are also allowed.

Comments

Single-line comments in Python are denoted by "#", multiline comments with three single quotes or three double quotation marks " or" "

1(" ")2 Luckynum = 63 For I in range (3):4 input_num = Int (input (' Please enter the number you want to guess: ') ')5 if Input_num > Luckynum:6 print (' The number you entered is too big! ')7 elif Input_num < luckynum:8 print (' The number you entered is too small! ')9 Else:Ten print (' Congratulations on your TM's guess! ') One  Break A Else: - print ("wrong guessing more than three times ~") - (" ") the  - #name = input (' Please enter your name: ')

Line and indent

Python is indented to represent blocks of code, and the same code block is indented in a consistent format, usually in the form of four spaces.

Data types and variables for Python

Data types in Python: integer (int), floating-point (float), Boolean (bool), character (string), null (None)

Integer

For example, 1, exactly the same as a mathematical integer.

Floating point number

For example, 0.11, a floating-point number is a decimal. Integers and floating-point numbers are stored internally in different ways, and integer operations are always accurate (is division accurate?), and floating-point arithmetic can have rounding errors.

Boolean type

Boolean type only True and False two values, for example

>>> 3>2True>>> 3>4False

Boolean values can be evaluated with and, or, not

The and operation is true with the result that only all of the results are true (true):

1  and True 2 True 3  and False 4 False 5  and False 6 False

An OR operation is an operation, as long as one of the true,or operation results is true;

1 or True 2 True 3 or False 4 True 5 or False 6 False 7

The not operation is a non-operation, and he is a monocular operator that turns true into False,false true:

1  not True 2 False 3  not False 4 True 5

Boolean values are often used in conditional judgments, such as

If age >= 18:print ' adult ' else:print ' teenager ' null null value is a special value in Python, denoted by none. None cannot be understood as 0, because 0 is meaningful, and none is a special null value.

Character type

Refers to the string

strings are enclosed in "or" " Strings!" What if the inside of a string contains both ' and contains '? You can use the escape character \ To identify, such as want to print I ' M "OK"!

>>> print (' i\ ' m \ "ok\"! ') I ' m "OK"!

The escape character \ can escape many characters, such as \ n for a newline character, \t for a tab, and the character \ itself to be escaped, so the character represented by \ \ is \, Try it in the interactive environment

 1  >>> print  ( '     )  "  m learning  3  python.  4  >>> print  ( '  

If there are many characters in the string that need to be escaped, it is impossible to add a lot of \, in order to simplify, Python runs with R ' ' means that the string inside of ' is not escaped by default

1 Print ('\\\t\\') 2 \     3 Print (R'\\\t\\') 4 \\\t\\

If there is a lot of line wrapping in the string, it is not good to read in a line, in order to simplify the use of "..." This means multiple lines of content

>>> print (' Q1 Q2 Q3 Q4 Q5 ') Q1 Q2 Q3 Q4 q5>>>

Python3 Data Type _1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.