Want to know beginning ruby from novice to professional? we have a huge selection of beginning ruby from novice to professional information on alibabacloud.com
Command line run Python scriptLinux first create a hello.py[Python] View PlainCopy
$ gedit hello.py
Input:[Python] View PlainCopy
#!/usr/bin/env python
Print 2
Save exit, run:[Python] View PlainCopy
$ python hello.py
4
We can also make it perform like a normal programBefore executing, let the script file have the executable properties:[Python] View PlainCopy
$ chmod a+x hello.py
To run the script:[Python] View PlainCopy
$.
Conditions and loopsConditional execution:Name = Raw_input (' What's your name? ' If Name.endswith (' Gumby '):p rint ' Hello, Mr.gumby 'What is your name? Gumbyhello, Mr.gumbyName = Raw_input (' What's your name? ' If Name.endswith (' Gumby '):p rint ' Hello, mr.gumby ' else:print ' Hello, stranger 'Multiple conditions:num = input (' Enter a number: ') if num > 0:print ' The number is positive ' elif num Enter a number:5the number is positiveEnter A number: -1the number is negativeEnter a numbe
Beginning Python From Novice to Professional (5)-conditions and loops
Conditions and loops
Conditional execution:
name = raw_input('What is your name? ')if name.endswith('Gumby'):print 'Hello, Mr.Gumby'
What is your name? GumbyHello, Mr.Gumby
name = raw_input('What is your name? ')if name.endswith('Gumby'):print 'Hello, Mr.Gumby'else:print 'Hello, stranger'Multi
Beginning Python From Novice to Professional (2)-run the Python script on the command line, novicepython
Run the Python script on the command line.
Create a hello. py file in Linux
$ Gedit hello. py
Input:
#! /Usr/bin/env pythonprint 2 + 2Save and exit. Run:
$ Python hello. py 4We can also make it run like a common program.
Before Execution, le
Beginning Python From Novice to Professional (9)-Socket, pythonnovice
Socket
Small servers:
#!/usr/bin/env pythonimport sockets = socket.socket()host = socket.gethostname()port = 1234s.bind((host,port))s.listen(5)while True:c,addr = s.accept()print 'Got connection from',addrc.send('Thank you for connecting')c.close()Small client:
#!/usr/bin/env pythonimport so
', ' little ', ' dog ']>>> sentence.index (' Little ') 3Insert inserts an object into the list:>>> num = [1,2,3,5,6,7]>>> num.insert (3, ' four ') >>> num[1, 2, 3, ' Four ', 5, 6, 7]Pop removes the list element, the last one by default:>>> x = [1,2,3]>>> x.pop () 3>>> x[1, 2]>>> x.pop (0) 1>>> x[2]Combined Append:>>> x = [1,2,3]>>> x.append (X.pop ()) >>> x[1, 2, 3]Remove removes the first occurrence from the list:>>> x = [' To ', ' is ', ' or ', ' not ', ' to ', ' is ']>>> x.remove (' is ') >>
]
>>> X.append (X.pop ())
>>> x
[1, 2, 3]
Remove removes the first occurrence from the list:[Python] View PlainCopy
>>> x = [' to ',' is ', 'or ',' not ',' to ',' is ']
>>> x.remove (' be ')
>>> x
[' to ', ' or ', ' no ', ' to ', ' being ']
Reverse Reverse storage elements:[Python] View PlainCopy
>>> x = [1,2,3]
>>> X.reverse ()
>>> x
[3, 2, 1]
Sort order:[Python] View PlainCopy
>>> x = [4,6,2,1,7,9]
Site optimization of the beginning of the first need to optimize the site is also the choice of host to work hard, good host can make your later SEO effort, poor main opportunity to make you mental haggard, even the impact of the site is disastrous. The following is the odd Fox SEO to novice host to choose a few suggestions, opinion for reference only.
First, try to choose the credibility of more trustwort
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.