You are on page 1of 2

print " " sau ' ' sau "' '" sau '" "'

+ plus
- minus
/ slash
* asterisk
% percent
< less- than
> greater- than
<= less- than- equal
>= greater- than- equal
, pune spatiu dupa
carpool_capacity = cars_driven * space_in_a_car #definire variabile, se pot face
operatii matematice cu ele
print "We need to put about", average_passengers_per_car, "in each car."
my_name = 'Zed A. Shaw' #variabila string
my_age = 35 #variabila numar
print "Let's talk about %s." % my_name
print "He's %d inches tall." % my_height
print "He's got %s eyes and %s hair." % (my_eyes, my_hair)
print "If I add %d, %d, and %d I get %d." % (my_age, my_height, my_weight, my_ag
e + my_height + my_weight)
%s #string (numai text)
%d #valoare sau numar
hilarious = False
joke_evaluation = "Isn't that joke so funny?! %s"
print joke_evaluation % hilarious
print "Its fleece was white as %s." % 'snow'
print "." * 10 #afiseaza de 10 ori ce-i sub ghilimele
formatter = "%r %r %r %r"
print formatter % (1, 2, 3, 4) #1 2 3 4
print formatter % ("one", "two", "three", "four") #'one' 'two' 'three' 'fo
ur'
print formatter % (True, False, False, True) #True False False True
print formatter % (formatter, formatter, formatter, formatter) #'%r %r %r %r'
'%r %r %r %r' '%r %r %r %r' '%r %r %r %r'
print formatter % ( #'I had this thing.' 'Th
at you could type up right.' "But it didn't sing."
"I had this thing.", #'So I said goodnight.'
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
)
\n intre ghilimele trece pe o linie noua ce este dupa el
\t introduce spatiu tab in fata la string
"""
in felul
asta poti introduce
un string pe mai multe randuri"""
\\ Backslash (\)
\' Single- quote (')
\" Double- quote (")
\a ASCII bell (BEL)
\b ASCII backspace (BS)
\f ASCII formfeed (FF)
\n ASCII linefeed (LF)
\N{name} Character named name in the Unicode database (Unicode only)
\r ASCII carriage return (CR)
\t ASCII horizontal tab (TAB)
\uxxxx Character with 16- bit hex value xxxx (Unicode only)
\Uxxxxxxxx Character with 32- bit hex value xxxxxxxx (Unicode only)
\v ASCII vertical tab (VT)
\ooo Character with octal value oo
\xhh Character with hex value hh
age = raw_input() #definire varsta cu introducere de la tastatura
raw_input() #introducere de la tastatura
print "So, you're %s old, %s tall and %s heavy." % (age, height, weight)
x = int(raw_input()) #definire valoare, numar pentru calcule matematice, numai
asa
y = raw_input("Name? ") #This prompts the user with Name? and puts the result in
to the variable y
from sys import argv
script, first, second, third = argv #trimitere argumente(paramet
ri) din command line in felul asta
print "The script is called:", script #programul le primeste si le
stocheaza ca variabile
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
from sys import argv #trimitere cu parametri
si asteptare raspuns (prompt) cu introducere raspuns prin raw_input()
script, user_name = argv #si memorare raspuns in
likes
prompt = '> ' #Notice though that we m
ake a variable prompt that is set to the prompt we want, and we give
print "Hi %s, I'm the %s script." % (user_name, script) #that to raw_input inste
ad of typing it over and over. Now if we want to make the prompt some-
print "Do you like me %s?" % user_name #thing else, we just cha
nge it in this one spot and rerun the script.
likes = raw_input(prompt)

You might also like