Python notes (1)

Source: Internet
Author: User

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)

Related Article

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.