Day5--python integer, floating-point, Boolean, and string

Source: Internet
Author: User
Tags abs

a) Integer name = raw_input ("Please input your name:") print (name) print (type (name)) type is the view type str is the character type  age = input ("please Input your Age: "Print (age) print (type)     If the input character, will be reported nameerror,input only receive numeric type (can receive decimal), recommended use Raw_ Input without the recommended input  a = 100b = -20print (a) print (b) print (-a) print (a.__abs__ () + b.__abs__ ()) Print (dir (a)) Print (ABS (a) +abs (b)) print (A/b)        ' __abs__ ' is the absolute value, ABS has this property, there is this ABS culvert number, the following is rarely used in the beginning of the dash, These methods can be rewritten by themselves, the number of methods commonly used is to find the absolute value _ _abs__ (two _ Underscore)     dir () built-in functions: Python built-in methods have many, The Dir () function is useful when both beginners and pass-through Python programmers can't remember all the methods. With the Dir () function you can see all of the methods within the image, in Python everything is a pair of like, a data type, a module, etc., all have their own properties and methods, in addition to the usual method, you do not need to remember it all, to the Dir () function is good.     dir () function use: the DIR () function is very simple, just want to query and write to () in parentheses can be used.    B) floating point     in floating-point operations, there are two ways to control the number of decimal points after the number of,    round () built-in methods     round ( The built-in method to take the decimal point precision is most commonly used.     when round (float) contains only numbers, it retains 1 decimal places by default and is rounded.     Examples are:       >>> Round (2.5)         3.0          >>>   Round (1.5)         2.0 a = 3.00b = 2.53c = 2.43print (Round (a)) print (round (b)) Print (Round (c )   Results: 3.0 3.0 2.0round ()     1. Default reserved one decimal place     2. The rounding method is used to calculate the   c = 2.555d = 1.545print ( Round (c,2)) print (round (d,2))   results:2.56    1.54    when round (float,ndigits) contains numbers and precision, float represents a number , the ndigits represents the precision that needs to be retained, and the general situation is the use of rounding rules (rounding first), but encountering. 5 in this case, if the number of digits before the trade-off is even, it is discarded directly, and if it is odd, it goes up one. In general, the last digit of the decimal point precision must be even           >>>  round (2.555,2)              2.56          >>>  round (2.545,2)  & nbsp          2.54      Boolean type two values, one is false, one is true, usually at the time of assignment, is a return value for the final judgment, and then the value is manipulated.     true    Falseprint (not True) A = 10b = 20print (not(A>b and C>a))           String definition     string is the most commonly used, "," "," "" "can be used to define a string, The most canonical method is to define a string, using the single quotation mark '  STR1 = ' aaa ' str2 = ' bbbbb ' STR3 = ' "" CCCCC "" "Print (STR1,STR2,STR3)   After printing the result is:

 

    Final printed string results are single quotes, print (type str1) type: <type ' str ' >print (dir (str1))     The function dir is used to see what Python data types are, there are many ways to print out, but we only introduce the most common methods, and later use other methods, we can find it by this method. To master these methods, just remember a few common words, these methods to easily solve the     underlined without looking [' capitalize ', ' center ', ' count ', ' decode ', ' encode ', ' endswith ', ' expandtabs ', ' find ', ' format ', ' Index ', ' isalnum ', ' isalpha ', ' isdigit ', ' islower ', ' isspace ', ' istitle ', ' isupper ', ' Join ', ' ljust ', ' lower ', ' lstrip ', ' partition ', ' replace ', ' rfind ', ' rindex ', ' rjust ', ' rpartition ', ' rsplit ', ' Rstrip ', ' Split ', ' splitlines ', ' startswith ', ' strip ', ' swapcase ', ' title ', ' Translate ', ' upper ', ' Zfill ']    Common methods of String: Find, replace, split, join, strip, format    string default is subscript, subscript is starting from 0,    s = ' Hello ' print (s [0],s[1],s[2])   return result: (' h ', ' e ', ' l ')  find: Find the string if it finds the subscript information that returns the first letter of the string, if the mismatch returns -1 s= ' 12345yangjinbiao ' Print (S.find (' YB ')) print (S.find (' Yang '))     A. Below is a Find method that returns the first letter of the substring where the string is located      Return results are:-1    5replace: Replace print (S.replace (' Jin ', ' 222 '))     Replace is what value is replaced by what value split: the equivalent of what is the delimiter, Equivalent to the "F" option of awk inside the shell s= ' [email protected]@@@@[email protected]@@@@[email protected]@@@ zzfcthotfixz ' Print (S.split ("))       results are:

join:s= ' [email protected]@@@@[email protected]@@@@[email protected]@@@ zzfcthotfixz ' print (' Hello '. Join (S.split ('))) Printing results are:

Day5--python integer, floating-point, Boolean, and string

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.