0% found this document useful (0 votes)
28 views3 pages

Import This: Python 2.7.6 (Default, Oct 26 2016, 20:30:19) (GCC 4.8.4) On Linux2 01

The document shows examples of using Python for basic string operations, loops, conditional statements, and list comprehensions. It imports and prints the Zen of Python philosophy, defines a string, prints and slices the string, uses for loops to iterate over ranges and the string, includes an if statement in a loop, and defines a lambda function to filter a list.

Uploaded by

Erw Dgdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Import This: Python 2.7.6 (Default, Oct 26 2016, 20:30:19) (GCC 4.8.4) On Linux2 01

The document shows examples of using Python for basic string operations, loops, conditional statements, and list comprehensions. It imports and prints the Zen of Python philosophy, defines a string, prints and slices the string, uses for loops to iterate over ranges and the string, includes an if statement in a loop, and defines a lambda function to filter a list.

Uploaded by

Erw Dgdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python 2.7.

6 (default, Oct 26 2016, 20:30:19)


[GCC 4.8.4] on linux2

01>>​ ​import this


The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

​ rint "hola mundo"


02>>​ p
hola mundo

03>>​ ​3 + 4
7

04>>​ ​"hola" + " mundo"


'hola mundo'

05>>​ print 'Alexa dijo "Hola!"'


Alexa dijo "Hola!"

06>>​ 2 * 3
6

07>>​ print 'Alexa dijo ' + 10 * "Hola!"


Alexa dijo Hola!Hola!Hola!Hola!Hola!Hola!Hola!Hola!Hola!Hola!

08>>​ ​x = 'Alexa dijo ' + 10 * "Hola!"


09>>​ ​print x
Alexa dijo Hola!Hola!Hola!Hola!Hola!Hola!Hola!Hola!Hola!Hola!

10>>​ ​type(x)
<type 'str'>

11>>​ ​len(x)
61

## INDEXACION ##

12>>​ x[0]
'A'

13>>​ x[0:4]
'Alex'

14>>​ x[0:5]
'Alexa'

15>>​ x[:5]
'Alexa'

16>>​ x[-1]
'!'

17>>​ x[-10:]
'Hola!Hola!'

18>>​ x[-5::2]
'Hl!'

19>>​ x[:-6:-1]
'!aloH'

## CICLOS ##

20>>​ for i in "hola!":


... print i
...
h
o
l
a
!
21>>​ for i in range(1,9):
... print i
...
1
2
3
4
5
6
7
8

## IF ##

22>>​ for i in range(1,9):


... if i%2:
... print i
...
1
3
5
7

## LISTAS ##

23>>​ [x for x in range(1,9) if x%2]


[1, 3, 5, 7]

24>>​ z = lambda p: [x for x in p if x%2]

25>>​ z(range(50,70))
[51, 53, 55, 57, 59, 61, 63, 65, 67, 69]

You might also like