Arquivo anexado 'HelloWorld.py'
Download 1 #!/usr/bin/python
2 # -*- coding: iso-8859-1 -*-
3
4 # Exemplos retirados do artigo: Python Cheat Sheet
5 # http://www.yukoncollege.yk.ca/~ttopper/COMP118/rCheatSheet.html
6 print "s = \"Hello World!\""
7 s = "Hello World!"
8 print "suffix = \".py\""
9 suffix = ".py"
10 print "prefix = \"py_\""
11 prefix = "py_"
12 print "substring = \"lo\""
13 substring = "lo"
14 print "chars = \"H\""
15 chars = "H"
16 print "list = []"
17 list = []
18
19 # Testing string contents:
20 print ">>> print \"Hello World!\".isalnum()"
21 print "Hello World!".isalnum()
22 print ">>> print \"Hello World!\".isalpha()"
23 print "Hello World!".isalpha()
24 print ">>> print \"Hello World!\".isdigit()"
25 print "Hello World!".isdigit()
26 print ">>> print \"Hello World!\".isspace()"
27 print "Hello World!".isspace()
28 print ">>> print \"Hello World!\".islower()"
29 print "Hello World!".islower()
30 print ">>> print \"Hello World!\".isupper()"
31 print "Hello World!".isupper()
32 print ">>> print \"Hello World!\".istitle()"
33 print "Hello World!".istitle()
34 print ">>> print \"Hello World!\".endswith( suffix )"
35 print "Hello World!".endswith( suffix )
36 print ">>> print \"Hello World!\".startswith( prefix )"
37 print "Hello World!".startswith( prefix )
38
39 # Finding things in strings:
40 print ">>> print \"Hello World!\".count( substring )"
41 print "Hello World!".count( substring )
42 print ">>> print \"Hello World!\".find( substring )"
43 print "Hello World!".find( substring )
44 print ">>> print \"Hello World!\".index( substring )"
45 print "Hello World!".index( substring )
46 print ">>> print \"Hello World!\".rfind( substring )"
47 print "Hello World!".rfind( substring )
48 print ">>> print \"Hello World!\".rindex( substring )"
49 print "Hello World!".rindex( substring )
50
51 # Changing stringprint s. Remember that strings are immutable so to make a change "stick" you have to do, e.g. s = print s.title().
52 print ">>> print \"Hello World!\".swapcase()"
53 print "Hello World!".swapcase()
54 print ">>> print \"Hello World!\".upper()"
55 print "Hello World!".upper()
56 print ">>> print \"Hello World!\".lower()"
57 print "Hello World!".lower()
58 print ">>> print \"Hello World!\".title()"
59 print "Hello World!".title()
60 print ">>> print \"Hello World!\".capitalize()"
61 print "Hello World!".capitalize()
62 print ">>> print \"Hello World!\".center(30)"
63 print "Hello World!".center(30)
64 print ">>> print \"Hello World!\".ljust(10)"
65 print "Hello World!".ljust(10)
66 print ">>> print \"Hello World!\".rjust(15)"
67 print "Hello World!".rjust(15)
68 print ">>> print \"Hello World!\".strip()"
69 print "Hello World!".strip()
70 print ">>> print \"Hello World!\".lstrip( chars )"
71 print "Hello World!".lstrip( chars )
72 print ">>> print \"Hello World!\".rstrip( chars )"
73 print "Hello World!".rstrip( chars )
74 # Mudança didatica.
75 chars = "Hel"
76 print ">>> print \"Hello World!\".lstrip( chars )"
77 print "Hello World!".lstrip( chars )
78 print ">>> print \"Hello World!\".rstrip( chars )"
79 print "Hello World!".rstrip( chars )
80 # Nova mudança didatica.
81 chars = "ld!"
82 print ">>> print \"Hello World!\".lstrip( chars )"
83 print "Hello World!".lstrip( chars )
84 print ">>> print \"Hello World!\".rstrip( chars )"
85 print "Hello World!".rstrip( chars )
86
87 # String to list:
88
89 print ">>> list = \"Hello World!\".split()"
90 print ">>> print list"
91 list = "Hello World!".split()
92 print list
93
94 # List to string:
95 print ">>> print s.join( list ) # where s is the string to join the elements of list with."
96 print s.join( list ) # where s is the string to join the elements of list with.
Arquivos Anexados
Para se referir aos anexos de uma página, use attachment:filename, como mostrado abaixo na lista de arquivos. NÃO use a URL do link [get], já que a mesma está sujeita a alterações, e pode facilmente se tonar inválida.Você não tem permissão para anexar arquivos a esta página.