Python_ Basic Command _01

Source: Internet
Author: User


About Linux


D: folder-: File

Rwx:4+2+1=7-wx:2+1=3-wx:2+1=3

chmod Touch ls cd nano tail man wget--help apt-get


-rw-r--r--1 bu users 2254 2006-05-20 13:47 tt.htm
From the second word character rw-is that the user bu has read, write right, no operation right, then the r--user group users only Read permission, no operation right, the last r--refers to other people (others) only read permission, no write right and run right.


Linux directory structure

/bin:bin is the abbreviation of binary. Store the most commonly used executables (binaries) in the system.

/boot: The Linux kernel and system boot files are stored here, including the GRUB, Lilo Launcher program.

/dev:dev is the abbreviation for device (devices). This directory contains Linux external devices, such as hard disks, partitions, keyboards, mice, USB, and so on.

/etc: This directory is used to store all the configuration files and subdirectories required for system management, such as passwd, hostname, etc.

/home: The user's main directory, in Linux, each user has a directory of their own, generally the directory name is named after the user's account.

/lib: A shared library file that contains many library files that are used by programs in/bin and/sbin.

/lost+found: This directory is generally empty, and when the system shuts down illegally, some scattered files are stored here.

/media:ubuntu system automatically mounts the CD-ROM, USB device, storage temporarily read in the file.

/MNT: mount point as mounted file system.

/OPT: As a storage directory for optional files and programs, it is primarily used by third party developers to easily install and uninstall their software.

/proc: This directory is a virtual directory, it is the mapping of system memory, we can access this directory directly to obtain system information. Here all the flags are stored for the process of the file, comparing the data that cpuinfo the current working state of the CPU.

/root: This directory is a user home directory for system administrators, also known as super-permissions.

/sbin:s is the meaning of super user, which is stored in the system administrator to use the system management programs, such as System management, directory queries and other key command files.

/SRV: Store the service data provided by the system.

/sys: System device and file hierarchy, and provide detailed kernel data information to user program.

/tmp: This directory is used to store temporary files, and all users have read and write access to this directory.

/usr: Stores files and directories related to the user of the system.

/usr directory specifically:

/USR/X11R6: The directory where the x-windows is stored;

/usr/games: Store the small game that the xteamlinux comes with;

/usr/bin: Standard commands for users and administrators;

/usr/sbin: The management program that holds the root superuser user;

/usr/doc:linux technical documentation;

/usr/include: Used to store the header files needed to develop and compile applications under Linux, for C or C + +;

/usr/lib: Connection libraries for applications and packages;

/usr/local: The application directory installed by the system administrator;

/usr/man: The directory where the Help document resides;

/usr/src:linux Open source code;

/var/cache: Application cache directory;

/var/crash: System error message;

/var/games: Game data;

/var/log: Log file;

/var/mail: e-mail;

/var/tmp: Temp file directory;

--------------------------------------------------------------------------------


2. Composition of data types


Composed of 3 parts.

Identity ID method take a look at his unique identifier, memory address by this Oh!

Type a look at it.

The value data item.


The Pride of a book conclusion: Python is a pointer to everything, so you don't have to think about pointers!




3. Common basic data types.

int integral type

Boolean boolean True False

String strings

list []

Tuple Ganso ()

Dict Dictionary {}




4. Variable and immutable data types


Immutable type: int,string,tuple-----Variable changes the value, as if the reference is re-directed, the ID will change

Variable type: list,dict-------variable change value, its ID is unchanged


s = "Opendaylight"

S[0] = 9//Error But if S is a list, then no problem


5. Assignment of variables everything is quoted, and the dynamic and dynamic types are no longer dynamic


6. Default ASCII one Chinese contains 3 bytes len (x) shows 3 X.decode (' Utf-8 ')

Encoding #coding=utf-8 a Chinese Len () displays a


7. \ escape


8.print r "\ n" u r

adding u before the preceding string tells Python that it is a Unicode encoding that is stored in Unicode format.

Plus r means no escaping in the back



9. String slicing

(1)

A = r "\nslakjspppppaslkjlmxisal"

Print A[-8:len (a)]//Negative number indicates inverted, packet left not packet right

(2)

The split method of the string, which returns the list


String substitution

A = r "\\\\\-------//////"

b = a.replace (r ' \ \ \ ', ' lksdlklll ')

Print B

lksdlkllllksdlklll\-------//////


string concatenation

(1) Formatted output


1) print "YIJIAER%SE%DR"% ("Dengyu", 20)//Use tuples here, one can not

YIJIAERDENGYUE20R//is not a formatted output in other languages


2) print "yijiaer% (c1) seggf% (C2) Dr"% {' C1 ': ' Dengyu ', ' C2 ': 20}//This is the way of the dictionary


3) print "Yijiaer{1}e{0}r". Format ("Dengyu")//in the form of a method, the effect is the same as the number can be specified by the tuple which one

Print "Yijiaer{c1}e{c2}r". Format (c1=20,c2= "Dengyu")//with Name can also


(2) Append method of the list

s = []

S.append (' abc ')

[' ABC ']

(3) Join method for strings

A = "AAAAA"

b = "BBBBB"

c = "CCCCC"

Print ",". Join ([a,b,c])//Use list here

String Lookup

A.find (' J ', 4)//not found return-1 returns the first matching index value

A.index (' j ')//No error found

A.rfind ()//Reverse Lookup

Please calculate the string a total of several commas

Print A.count (', ')


10. File Read Write

A = open (' A.text ', ' w ')//Create file object, path is default +a.text no words will be created directly, permission is write

A.write ("Kjdkkk\nlkadd")//write content (String)

A.close//Close object, Java should be closed stream

b = Open (' A.text ', r)//create object, specify path, permission is read

Print B.read (20)//Read 20, the cursor will stop at 20

B.seek (0)//reset required to 0


Import Linecache//for reading

Getline ()//Self help, actually also open





This article is from the "Try" blog, so be sure to keep this source http://beening.blog.51cto.com/9079117/1812436

Python_ Basic Command _01

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.