1. Variables, types, operations, outputs, etc. #-*-coding:utf-8-*-a=2b=3C=a+bprint u'The result is =%i .'%C #加u显示中文str=unicode (s),"Utf-8") #转s为中文print str#int type and string type cannot be directly connected # Convert string concatenate and convert numbers plus minus d="1111"e=a+int(d) Print"c is%s,e are%i"%(c,e) F=Teng=3h=Ten/3Print U'h=%f'%h #输出3.000000h=10.0/3Print'h=%f'%h #输出3.3333332. Comment # single-line comment" "Multi-line comments2. String Operators%s string (shown with str ())%R string (shown with repr ())%C Single character%b -binary integers%d decimal Integer%I decimal integer%o octal integer%x hexadecimal integer%e index (base written as E)%e index (base written as E)%F floating point number%F Floating-point number, same as above%G Index (e) or floating point number (depending on display length)%G Index (E) or floating point number (depending on display length)Percent of characters "%"3. Python data type1, String2, Boolean type3, Integer4, floating point5, Digital6, List7, tuples8, Dictionaries9, Date1, string A, using single quotation marks (')enclose a string in single quotation marks, for example: Str='The is string';p rint str;b, use double quotation marks (")the string in double quotation marks is exactly the same as the string usage in single quotes, for example: Str="The is string";p rint str;c, use three quotation marks (" ")Use three quotation marks, which represent multiple lines of string, that can be used freely in three quotation marks and double quotation marks, for example: Str=" "The is string This isPythodstring This is string" "print str;2, Boolean typeBOOL=False;printBOOL;BOOL=True;printBOOL;3, Integerint= -;p rintint;4, floating pointfloat=2.3;p rintfloat;5, numbers include integers, floating-point number. 5.1, delete a numeric object reference, for example: a=1; b=2; c=3;d El A; #删除变量del b, C; #print A; #删除a变量后, then call a variable will error5.2, numeric type conversion copy Codeint(x [,Base]) to convert x to an integerfloat(x) convert x to a floating-point number complex (real [, Imag]) creates a complex number str (x) to convert object x to a string repr (x) converts an object x to an expression string eval (str) used to evaluate a valid Python expression in a string. and returns an object tuple (s) converts the sequence s to a tuple list (s) converts a sequence s into a list Chr (x) converts an integer to a character unichr (x) converts an integer to a Unicode character, Ord (x) converts a character to its integer value hex (x) converts an integer to a hexadecimal string Oct (x) converts an integer to an octal string str="[A]"arr=eval (str) print arr
Python notes (1)