Print Function and Strings


The print function in Python is a function that outputs to your console window whatever you say you want to print out. At first blush, it might appear that the print function is rather useless for programming, but it is actually one of the most widely used functions in all of python. The reason for this is that it makes for a great tool.

"Debugging" is the term given to the act of finding, removing, and fixing errors and mistakes within code.

If something isn't acting right, you can use the print function to print out what is happening in the program. Many times, you expect a certain variable to be one thing, but you cannot see what the program sees. If you print out the variable, you might see that what you thought was, was not.

You can follow this tutorial with the video and the embedded console, via the text and consoles, or via your own installation of Python.



Next up, strings, what are they? Strings are just "strings" of text, hence the name. Strings are a type of data. Another type of data is integers.

To build on the video, here are some examples:

print('Single Quotes')
print("double quotes")
		

We're printing out a string. Notice that the quotes are single quotes. You can use single quotes or double quotes, but they need to be used together.

While we're talking about strings and the print function, it would be useful to discuss concatenation. Concatenation just means the combination of things. You can use the "+" or the "," to join strings together. If you use a ",", then you will have a space in between the strings you joined. If you use a "+", then the strings will be strung together with no space. You will need to add one if you wanted.

If you use the "+" to join integers and floats together, then you will perform an arithmetic operation. If you use the ",", then it will print them out separately, with a space.

print('can do this',5)
		
print('cannot do this:'+5)
		

You cannot use the "+" to join strings with ints or floats, you must use the ",".

It is also important to bring up how to put quotes within strings. You can either put double quotes inside single quotes, singles inside doubles, or use the "\" backslash. The \ character is known as an , and it will "escape" the characteristic of the following character and just take on the 'visual' aspect of it.

The purpose of the "escape character" is to escape various characteristics for characters. For example, a quotation, ", in a string might wreak havoc. Take for example: x = "He said, "Hello there!" "

Yeah, that's going to be a problem. There are obviously many options to avoid this specific problem, but one of them would be to use an escape character:

x = "He said, \"Hello there!\" "

If you do a print(x), you will not see the escape characters, and you will see the quotes. Sometimes you want to show the escape character as well:

x = "An escape character is a \"

How might you solve that?

Here are some examples of quotation rules:

print('Can't do this')
		
print('you\'ll have success here')
		
print("you'll have success here too")
		

It is also important to bring up how to put quotes within strings. You can either put double quotes inside single quotes, singles inside doubles, or use the "\" backslash. The \ character is known as an "escape" character, and it will "escape" the characteristic of the following character and just take on the 'visual' aspect of it. Here are some examples of quotation rules:

That covers the basics of strings for now.


There exists 2 quiz/question(s) for this tutorial. for access to these, video downloads, and no ads.

The next tutorial:





  • Python Introduction
  • Print Function and Strings
  • Math with Python
  • Variables Python Tutorial
  • While Loop Python Tutorial
  • For Loop Python Tutorial
  • If Statement Python Tutorial
  • If Else Python Tutorial
  • If Elif Else Python Tutorial
  • Functions Python Tutorial
  • Function Parameters Python Tutorial
  • Function Parameter Defaults Python Tutorial
  • Global and Local Variables Python Tutorial
  • Installing Modules Python Tutorial
  • How to download and install Python Packages and Modules with Pip
  • Common Errors Python Tutorial
  • Writing to a File Python Tutorial
  • Appending Files Python Tutorial
  • Reading from Files Python Tutorial
  • Classes Python Tutorial
  • Frequently asked Questions Python Tutorial
  • Getting User Input Python Tutorial
  • Statistics Module Python Tutorial
  • Module import Syntax Python Tutorial
  • Making your own Modules Python Tutorial
  • Python Lists vs Tuples
  • List Manipulation Python Tutorial
  • Multi-dimensional lists Python Tutorial
  • Reading CSV files in Python
  • Try and Except Error handling Python Tutorial
  • Multi-Line printing Python Tutorial
  • Python dictionaries
  • Built in functions Python Tutorial
  • OS Module Python Tutorial
  • SYS module Python Tutorial
  • Python urllib tutorial for Accessing the Internet
  • Regular Expressions with re Python Tutorial
  • How to Parse a Website with regex and urllib Python Tutorial
  • Tkinter intro
  • Tkinter buttons
  • Tkinter event handling
  • Tkinter menu bar
  • Tkinter images, text, and conclusion
  • Threading module
  • CX_Freeze Python Tutorial
  • The Subprocess Module Python Tutorial
  • Matplotlib Crash Course Python Tutorial
  • Python ftplib Tutorial
  • Sockets with Python Intro
  • Simple Port Scanner with Sockets
  • Threaded Port Scanner
  • Binding and Listening with Sockets
  • Client Server System with Sockets
  • Python 2to3 for Converting Python 2 scripts to Python 3
  • Python Pickle Module for saving Objects by serialization
  • Eval Module with Python Tutorial
  • Exec with Python Tutorial