Python self-study days--one Day notes-string concatenation + if while for loop

Source: Internet
Author: User

Comments
Single-line Comment #
Multiline comment ' three single quotation mark or three double quotation mark ""

"' use three quotation marks to enclose multiple lines of assignment

User interaction Input

string concatenation
+ "% ()" ". Format () Recommended use
Name = input ("Name:")
age = Int (input ("Age:"))
Sex = input ("Sex:")
Example: +
# string concatenation +
INFO1 = "----info in" + name + "'---
Name: "+ name +"
Age: "+ Age +"
Sex: "+ sex +"
‘‘‘
Example: ""% ()
#% formatted string
info = "'------info in%s-------
name:%s
age:%d
sex:%s
"% (" name "," name ", Age," sex ")

# "". Format ()
INFO3 = "---info in {_name}---
Name:{_name}
Age:{_age}
Sex:{_sex}
". Format (_name=name,
_age=age,
_sex=sex)
Info4 = "---info in {0}---
NAME:{0}
Age:{1}
SEX:{2} ". Format (name, age, Sex)

Module definition:
Ciphertext password: Getpass use after reference, Getpass.getpass ()
If Else uses
Cases:
Username = "username"
Password = "123456"
_username = Input ("Username:")
_PASSWD = Input ("Password:")
If username = = _username and Password = = _passwd:
Print ("Welcome user {Name} to Beij". Format (Name=username))
Else
Print ("Invalid username or passwd")

If elif Else
Cases:
Myage = 37
inputage = Int (input ("Please input my Age:"))
if inputage = = Myage:
Print ("It ' s Right")
Elif inputage > Myage:
Print ("Think small")
Else
Print ("Think big")

While else loop
Count = 0
While Count < 3:
Myage = 37
inputage = Int (input ("Please input my Age:"))
if inputage = = Myage:
Print ("It ' s Right")
Break
Elif inputage > Myage:
Print ("Think small")
Else
Print ("Think big")
Count+=1
Else
Print ("Fuck you!")

Break jumps out of the current entire loop
Continue jump out of the current loop and into the next loop

Homework

Writing the Login interface

    • Enter User name password
    • Show welcome message after successful authentication
    • Three-time error after locking
Old_uname =OpenR ' C:\Users\Administrator\Desktop\username.txt ',' R '). ReadLines ()
Count =0
While Count <3:
Username =Input"Please your username:")
passwd =Input"Please your passwd:")
For IIn Old_uname:
If i = = Username:
Print"Wolcome to your Blogs:{_uname}". Format (_uneme=username))
Break
Else
Continue
Else
Count + =1
if Count = =3:
Continue
print ( else:
" three errors, account locked open (r" C:\Users\Administrator\Desktop\ Lockname.txt ' "a"). Write (username +

String Base
(1), Escape string              
(2), raw string--escape mechanism   open (R ' C:\tmp\a.txt ', ' A + ')
(3), Unicode string
(4), formatted string   "age%d,sex%s,record%" M.nf "% (," man ", 73.45)
String base operation
 + connection, * Repeat, S[i] Index (index), s[i:j] slice (slice), for loop traversal

Python self-taught days--one Day notes-string concatenation + if while for loop

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.