Python Basic Practice (i)

Source: Internet
Author: User

-*-paper on the end of the light, I know this matter to be gong. -*-
#-*-Coding:utf-8-*-
# Author:sweeping-monk
Name = "What is a string?" "
what_is_a_string = "String is a series of characters, in Python, enclose the string in quotation marks, where the quotation marks can be single quotes or double quotes. "
Print (name)
Print (what_is_a_string)

Question_1 = "What method is used to modify the case of a string?" "
Method_1 = "The program results are as follows:"
Print (question_1)
Print (method_1)
Name_one = "Ada Lovelace"
Print (Name_one.title ()) #.title () does not add any parameters to capitalize the first letter. Methods are the operations that Python can perform on the data.
Print (Name_one.lower ()) #这个方法可以将字符串转换成小写, which is useful when storing data.

Question_2 = "Merging and stitching Strings"
Method_2_1 = "The program results are as follows:"
Print (question_2)
Print (Method_2_1)
last_name = "Liu"
Name_1 = "Xiaole"
Full_name = last_name + name_1
Print (Full_name)
Full_name = last_name + "" + name_1 #引号内是空格
Print (Full_name)
Full_name = last_name + "_" + name_1 #引号内是下划线_, not repeat below.
Print (Full_name)
Message = "Hell wolrd," + Full_name + "!"
Print (message)

Question_3 = "How do I add blanks using tabs and newline characters?" "
Conception = "in programming, whitespace refers to any nonprinting character, such as spaces, tabs, newline characters. "
Method_3_1 = "The program results are as follows:"
Print (Question_3)
Print (conception)
Print (Method_3_1)
Print ("Programming language:" "Python")
Print ("Programming Language:" "\npython") #换行用换行符 \ n.
Print ("Programming Language:" "\n\tpython") #另一行开头空两格, with a tab \ t.
Print ("Programming Language:" "\n\tpython\n\tc++\n\tjava") #配合使用.

Question_4 = "How do I remove whitespace?" "
Conception_4_1 = "Blank is important because we often have to compare two strings in actual work, such as checking the user name when logging in to a website"
Method_4_1 = "program is executed under CMD terminal python3:"
Print (Question_4)
Print (Conception_4_1)
Print (Method_4_1)
Cmd_d = "'
Xiaolefdemacbook-air:ji_chu xiaole$ Python3 #请在cmd命令行下操作才能看到结果.
Python 3.6.3 (V3.6.3:2C5FED86E0, Oct 3 2017, 00:32:08)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on Darwin
Type "Help", "copyright", "credits" or "license" for more information.
>>> name = ' Python '
>>> Name
' Python '
>>> Name.rstrip ()
' Python ' #只是临时把空白给删除了.
>>> Name
' Python ' #再执行空白又恢复了.
>>> name = Name.rstrip () #永久删除空白的方法是把删除的结果: ' python ' is stored back in the original variable, which is a common method.
>>> Name
' Python '
>>> name_1 = ' python '
>>> Name_1.rstrip () #删除后面空白的方法
' Python '
>>> Name_1.lstrip () #删除前面空白的方法
' Python '
>>> Name_1.strip () #一起删除前后的方法.
' Python '
‘‘‘
Print (Cmd_d)

Python Basic Practice (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.