Python records-Getting Started to practice-string manipulation (i)

Source: Internet
Author: User
Tags arithmetic

I follow the book, summarize the implementation to record, do not feel simple to try, knock a code. Executive power is the sword of a good programmer. If you are a novice in mastering other language situations such as Java, C or PHP and so on any kind of basic grammar, the program is all the same, you can follow my record and I will step-by-step learning python.The Scarlet Letter is to pay attention to the place, during python2 and Python3 differences need to note that I will also be Red character logo. 1. Modify String Case
Name="ABC myname"print(Name.title ()) < turn capital Letter >
Print  (Name.upper ()) < go all caps > Print  (Name.lower ()) < turn all lowercase > #输出:
ABC myname
ABC MYNAME
ABC MyName
2. Stitching strings and tabs and line breaks
First_name="py"last_name="Thon"Full_name=first_name+" "+last_name < quotation marks in the middle is a space if you do not add a space, you only need a quotation mark connection >message="Hello,"+full_name.title () +"!"Print(message)
#输出:
Hello,py Thon
-------------------------------------------------------------------------------
Print("ABC\NABC\N\TABC")</n: line-break/t-tab >
#输出:
Abc
Abc
Abc
3. Remove string whitespace
My_name=""My_name.retrip () My_name.lstrip () My_name.strip ()# output:  "  python" "" "Python" 
4. Digital

As with other grammars (+) plus (-) minus (*) multiply (/) divide (*) the second party.

Floating point operations Note that the inclusion of decimal places is indeterminate, such as JavaScript arithmetic floating-point, where many languages can have multiple decimal places, because the numeric type of JavaScript is stored in the 64-bit IEEE 754 format.

can Baidu "python Reserved Decimal place" processing
0.2+0.1
#输出0.30000000000000004

Python2 and python3 floating point arithmetic difference note:

# python2.73/2# output 1#python2.73.0/2# output 1.5#  python33/2# output 1.5

Numeric and string combinations, note that numbers need to be specified as numbers of type int and string combinations to be numeric to string characters

age=23Name="zc"message=" my name is "+name+ STR (age) +" year old "print(message)# output My name is zc23 years old.

Python records-Getting Started to practice-string manipulation (i)

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.