First class basic data types

First class basic data types

A numerical type

  1, numeric types (four kinds)

int a = 1 #int
b = 1.1 #float float
c = True #bool Boolean True and False only two kinds
d = 1 + 2j #complex complex-type

  2, numerical operations

+ - * / # Math
// # divisible
% # Remainder
** # exponentiation
a+=1       #a=a+1
a*=1        #a=a*1

  3, variable naming rules

    Variable letters, numbers, underscores, beginning with the letters and underscore, can not use the keyword

  4, general keywords

print # Output
View object type type #
help # help
View object id id #
dir (__ builtins__) # View all the keywords

Second, sequence type

  1, the string str 

s='hello'  #str 
s = '' abc '' # double quotation marks and three are 
s = '' 'avx' '' # three marks can also be used to annotate

  2, in list

li = [] # Empty list
li = [1,2,3] #list in brackets elements are separated by commas

  3, tuple tuple

tu = (1,2) # of elements inside the parentheses, separated by commas
tu = 1,2 # parentheses may not, be separated by a comma
Words tu = 1, # only one element needs a comma

  4, Index

li [0] # index starts from 0, li [0] represents an index value of 0

  5, sliced

= [1,2,3,4,5]
li [1: 3] = [2,3] # represents the value of index 1 to index 2 slices left close right open following the principle (that is, left to obtain the right to get any) 

  6, step

= [1,2,3,4,5,6,7,8]
li [1: 8: 1] # slice index starting at index 1 to 7, the step size (i.e. slice interval) of 1
li [-1: -3: -1] # inverted index

  7, the sequence of operations

    Must be the same type of operation: + =, - =, * =

  8, check members

    in: In

    not in: not

  9, casts (engineering)

int () # rounded down, not to the string, complex-type rounding
str () # characters into a string
list () # is converted to a list
tuple () # conversion tuple

Third, work

  1, python inside how commented code

    number 1

    2, string

  2, there is a time in the form of (20,180,105), divisible by and take the remainder to obtain the corresponding day, month and year. Complete with a code.

time=20180105
month=time%10000//100
day=time%10000%100
year=time//10000
Output: 151,018

 

Guess you like

Origin www.cnblogs.com/sysun110/p/11267550.html