How to Print in Python

(4 votes, average 4.50 out of 5)

Printing in Python is as simple as typing print followed by the string you wish to print.  You do not need to import any libraries.

1
2
>>> print "Hello World"
Hello World

 

You can also print the value of an integer or list simply by print

1
2
3
4
5
6
>>> x = [1, 2, 3]
>>> print x
[1, 2, 3]
>>> y = 2
>>> print y
2

If, however, you want to print a string AND some integer (or list), you need to cast to string.

1
2
3
>>> x = 42
>>> print "The meaning of life is " + str(x)
The meaning of life is 42


Some notes about print:

Partner Links:
Last Updated on Saturday, 26 June 2010 10:53  
Related Articles

» How to Keep a Window Always on Top in Windows

Each iteration of Windows has welcomed some great functionality, but it still lacks an ability which can be very useful: keeping a window permanently visible.  Having a video or reference document visible can be great while trying to multi-task in other windows. Thankfully, third-party solutions exist to work around this problem.All that is needed is a quick, simple download.  Download from box.net, and unzip it somewhere easily accessible (such as your desktop).  Run the...

» Oracle 9.2.0 Error: System.Data.OracleClient requires Oracle client software version 8.1.7

ProblemWhen using a version of Oracle 9.2.0 in ASP.NET, attempting to access a site which uses System.Data.OracleClient may give an error with the following exception:  System.Data.OracleClient requires Oracle client software version 8.1.7 or greater This is a common error when using ASP.NET with Oracle -- it is in fact a bug in the default Oracle 9.2.0 installation permissions.  To fix the error, follow the following solution steps (taken from cited source): Log on to...

» How to Get a Visual Studio Solution Path in C#

Getting a path to the current solution in C# can be difficult because the idea of a Visual Studio solution is abstracted away from the actual code that is running.  But not all is lost -- Visual Studio builds it's binaries into the same location unless you specify them otherwise, and we can use this to our advantage.  For instance, if you have some project ExampleProject,  obtaining the current path while running the code would look result in this: [solution...