Python data types and basic operators

Source: Internet
Author: User

1. Data type

(1) What is a data type?

Variable values are the data we store, so data types are different types of variable values

(2) why the classification type ?

The value of the variable is to preserve the state of the real world, and it should be expressed in different types for different states.

(3) How to use? What are the types?

integer int access age, mobile number

Float Float- height, weight, salary

(4), String type str

A state, such as a name or address, that describes a property.

Defined:

in single quotation marks, double quotes, three quotes containing a series of characters (three quotes can write multiple lines)

name = ' QQC '

How to use it?

string types can only be : + or *

(5), list type

Function: Used to access multiple values

Definition: Separate multiple values of any type with commas in ""

How to use it?

(6) dictionary dict

function: Used to access multiple values, according to the Key:value to store the value, the time can be obtained by key rather than index to the value,key to Value is a descriptive function;

How to define: {} separate multiple elements with commas, no element is key:value format, where Value can be any type,key Most are string types

(7), Boolean type bool

The condition used for making judgments

definitions:ture and false

2. Formatted output

%s string placeholder (can receive a value of any data type) %d digit placeholder (can only receive shaping

Name = input (' Name: ')

age = Int (input (' Age: '))
Sex = input (' Sex: ')
Job = input (' job: ')

info = ""
%s Info of%s-------
Name:%s
Age:%s
Sex:%s
Job:%s
-----------End--------------
'% ('-' age,sex,job, name, name, ')
Print (info)

3. Basic Operators

A = b -=10 chain Assignment
A = 100
b = 200
A, B = b,a #交叉赋值
Print (A, B)

Python data types and basic operators

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.