Wednesday, September 24, 2008

Quickbooks Premier Product Number

4) Here we go: The string variables

To varying means, a portion of memory that can be changed during program execution. It's that simple! If we wanted to create a string variable just write

string = "hello world" # The variable becomes a string
print string # print-screen the string

What's happening? print, as we saw in the previous lesson, press the screen in this case the variable contains a string and we just read the string. We said that the variables can be changed during program execution so if you write well?

string = "hello world" # variable has the value "hello world" string
= "Hello World" here instead becomes # hello world "
print string

What's happening? In this case, the string variable value change at the beginning is "hello world" in the line next sequence becomes "Hello World". If you do a test print you will find that video print "Hello World" becomes the ultimate value that the variable string. You can assign any name to the variable except those reserved to python:

else for continuous and not raise import

assert def except from in or return
global break exec is try
class pass elif if finally lambda print while

How to concatenate variables: If we wanted to join
2 o più variabili potremi usare il simbolo " + " in questo modo:

stringa = "Hello " #da notare lo spazio lasciato alla fine prima dell apice
stringa2 = "world"
print stringa + stringa2

in questo caso output (il risolutato che ne consegue) sarà questo:

Hello world

Per fare delle prove (e vi consiglio di farne tante per restarvi in mente) usate il metodo usato nella lezione precedente create un file chiamato prova.py e fatelo eseguire dal terminale con python prova.py

Che sono quelle frasi dietro # ?? Si tratta di un commento, potete scrivere i vostri commenti a fianco al codice in modo tale da prendere appunti su quello che fà il programma sono utilissimi e vi consiglio di utilizzarli il più possibile.

Esercizio: Create 3 variabili che concatenate formino una frase di senso compiuto

0 comments:

Post a Comment