background image

"'Hello, world.'"

>>> 

str

(

1

/

7

)

'0.14285714285714285'

>>> 

=

 

10

 

*

 

3.25

>>> 

=

 

200

 

*

 

200

>>> 

=

 

'The value of x is '

 

+

 

repr

(x) 

+

 

', and y is '

 

+

 

repr

(y) 

+

 

'...'

>>> 

print

(s)

The value of x is 32.5, and y is 40000...

>>> 

# The repr() of a string adds string quotes and 

backslashes:

... 

hello 

=

 

'hello, world\n'

>>> 

hellos 

=

 

repr

(hello)

>>> 

print

(hellos)

'hello, world\n'

>>> 

# The argument to repr() may be any Python object:

... 

repr

((x, y, (

'spam'

'eggs'

)))

"(32.5, 40000, ('spam', 'eggs'))"

Εδώ   είναι   δύο   τρόποι   για   να   γράψει   έναν   πίνακα   των 

τετραγώνων και των κύβων:

>>> 

for

 x 

in

 

range

(

1

11

):

... 

    

print

(

repr

(x)

.

rjust(

2

), 

repr

(x

*

x)

.

rjust(

3

), end

=

' '

)

... 

    

# Note use of 'end' on previous line

... 

    

print

(

repr

(x

*

x

*

x)

.

rjust(

4

))

...

 1   1    1
 2   4    8
 3   9   27
 4  16   64
 5  25  125
 6  36  216
 7  49  343
 8  64  512
 9  81  729
10 100 1000

>>> 

for

 x 

in

 

range

(

1

11

):

... 

    

print

(

'{0:2d} {1:3d} {2:4d}'

.

format(x, x

*

x, x

*

x

*

x))

...

 1   1    1
 2   4    8

http://arch.icte.uowm.gr

 - A Mini greek notebook for Learning Python Programming 

50