Initial knowledge of user input and module in Python basics _python

Source: Internet
Author: User

I. Notes

Current line Comment: # Annotated content

Multiline Comment: "" "Annotated Content" ""

Second, user input

#!/usr/bin/env python
#_ *_coding:utf-8_*_
#name = Raw_input ("What is your name?") #only on python 2.x
name = i Nput ("What is your name?")
Print ("Hello" + name)

When you enter a password, if you want to be visible, you need to take advantage of the Getpass method in the Getpass module, namely:

#!/usr/bin/env python
#-*-coding:utf-8-*-
import getpass
# Assign user-entered content to name variable
pwd = Getpass.getp Ass ("Please enter a password:")
# Print the content printed
(PWD)

Third, format string

Formatted output of strings

Name = "Alex"
print "I am%s"% name 
# output: I am Alex
PS: string is%s; integer%d; floating point number%f

Iv. Initial understanding of the module

The power of Python is that he has very rich and powerful standard libraries and third-party libraries, and that almost any functionality you want to implement has a corresponding Python library support.

#!/usr/bin/env python
#-*-coding:utf-8-*-
import os
os.system ("Df-h") #调用系统命令

Write your own tab module, you will find that the above written tab.py module can only be imported in the current directory, if you want to be in the system where to use how to do it?

At this point you have to put this tab.py into the Python Global environment variable directory, basically in a directory called Python/2.7/site-packages, the directory in different OS place is not the same, with print (Sys.path) You can view a list of Python environment variables.

The above is a small set to introduce the basics of Python user input and the beginning of the module to understand, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.