Python Basic Concept Learning notes

Source: Internet
Author: User

This collation Python data type is:

    1. Lists List

    2. Dictionary Dict

    3. Tuple tuples

    4. Set Set


It involves the concept of:

    1. Module module

    2. Classes Class

    3. Objects Object


——————————————————————————————————————————

DataType type

Tuple tuples

Immutable sequences

How to create

(' A ',)

Tuple (' abc ')

Call Data Mode

T[0] is called the first character, and so on

Lists List

Variable sequence

How to create

List (' abc ')

[' A ']

Call Data Mode

L[0] is called the first character, and so on

Slice: list[strat:end:steps]

Dictionary Dict

Key:vaule Collection

How to create

Dict (Key:vaule)

{' A ': 1}

Call Data Mode

D[' A '] is invoked on key to invoke Vaule

Set Set

Unordered hash character sequence, non-repeating

Remove list duplicate data: List (set (' A ', ' a ', ' B '))

How to create

Set (' abc ')

Set operation

The collection |

Intersection &

Difference Set-

Differential set ^

Module module

A python file that contains functions and variables that can be called simultaneously by multiple scripts

Invocation mode

Import (module name)

Use functions: module name. function name

Import (module name) as (new module name)

Import (function name) from (module name)

function can be used directly

__name__ Property

The default value is "__main__", which becomes the module name after import

if __name__ = = ' __main__ ':

print ' This program was being run by itself '

Else

print ' I am being imported from another module '

Classes Class

Objects with the same properties and methods

Class is equivalent to a built-in module that can be called multiple times within the current script

__init__ function

This function is called when creating an instance of the class (Calling the Class), where the initialization of the object can be implemented

Necessary?

Formal parameter Self

A class is like a blueprint, using a class can create multiple object instances, and the Self argument tells which object is called, which is called the instance invocation

>>> class PEO:

def __init__ (self,name,age,sex):

Self. Name = Name

Self. Age = Age

Self. sex = Sex

def speak (self):

print "My name" + self. Name

>>> Zhangsan=peo ("Zhangsan", +, ' man ')

>>> print Zhangsan. Age

24

>>> Zhangsan.speak ()

My Namezhangsan

>>> Peo.speak (Zhangsan)

My Namezhangsan



Python Basic Concept Learning notes

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.