Python notes 2

Source: Internet
Author: User

Show user input
user = Raw_input (' Enter first Name: ')//raw_input is a built-in function
====> Enter first Name: root
print ' name is: ', User===>name is:root

int () string to digit
num = Raw_input (')
1024
print '%d '% (int (num) *2)
2048

#为注释

Symbol: +,-,*,/. Basic symbols
Floating-point division,% remainder, * * exponentiation
comparison operator >,>=,<,<=,==,!=
Logical operations: and OR not

Number type: Int,long,bool,float,complex
String: pystr= ' Python '
Iscool = ' is cool! '
Pystr[0]===> ' P '//Take first character
Pystr[2:5]===> ' tho '//Fetch 2--5 Index
Iscool[:2]==> ' is '//fetch from head to index 2
Iscool[3:]==> ' cool! ' Index 3 to the end
Iscool[-1]===> '! ' Take the last one.
Pystr+iscool===> ' Pythonis cool! ' Character connection
pystr+ ' +iscool==> ' Python is cool! '
Pystr*2===> ' Pythonpython '/output 2 times
' _ ' *20===> ' ____________________ '/output 20 _
Pystr= ' python
. are cool ' '
Pystr===> ' Python/nis cool '
Print Pystr====>python
are cool


Arrays and meta data
Alist =[1,2,3,4]
alist===>[1,2,3,4]
Alist[0]===>1
alist[2:]===>[3,4]
alist[:3]===>[1,2,3]
Alist[1]=5
alist===>[1,5,3,4]

Tuples cannot be modified
Atuple = (' robots ', 77,93, ' try ')
Atuple===> (' Robots ', 77,93, ' try ')
Atuple[:3]==> (' robots ', 77,93)
Atuple[1]=5//Error

Dictionary//similar map
Adict = {' host ': ' Earch '}
adict[' Port ' = 80
adict===>{' host ': ' Earch ', ' Port ': 80}
Adict.keys () ==>[' host ', ' Port '
adict[' host ']===> ' earch '

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.