Hi,
I have just started to learn python. I have installed and set the environment variables as per documentation. And from command prompt, I execute some python script,too. But I can't execute multiple line script, if the script contains any function. For example, see the following code -

>>>a,b=0,1
>>>print a,b

It successfully prints the value of a and b.

But if I want to execute following types of script -

str1 = "Hello Monty Python!"
str2 = str1.replace('M', 'Spam')
str3 = str2.replace('P', 'Spam')
print( str1 )
print( str2 )
print( str3 )

I am not able to write this type of script in command line.
When I write the first Print statement i.e. print(str1) and press enter,
it prints the value of the str1.
Please suggest how to write this type of code in command line.

Thanks and regards,

print('\n'.join((str1, str2, str3)))

maybe?

Thanks Tony, I will try this one.
But it is not possible having three different Print statement as given in my code snippet?

print('\n'.join((str1, str2, str3)))

maybe?

Maybe like this.

str1 = "Hello Monty Python!"
str2 = str1.replace('M', 'Spam')
str3 = str2.replace('P', 'Spam')
def print_str(str1, str2, str3):
    print(str1)
    print(str2)
    print(str3)
print_str()

or

str1 = "Hello Monty Python!"
str2 = str1.replace('M', 'Spam')
str3 = str2.replace('P', 'Spam')
print('%s\n%s\n%s' % (str1, str2, str3))
>>> from __future__ import print_function
>>> str1 = "Hello Monty Python!"
>>> str2 = str1.replace('M', 'Spam')
>>> str3 = str2.replace('P', 'Spam')
>>> print( str1 ); print( str2 ) ; print( str3 )
Hello Monty Python!
Hello Spamonty Python!
Hello Spamonty Spamython!
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.