Creating your First Python Program

Lab Details:

  1. This lab walks you through the Print function in Python.

  2. Duration: 20 minutes

Note: Do not refresh the page after you click Start Lab, wait for up to 15 seconds to load the lab resources.

Why Python?

  • Python is dynamically typed which means that you don't declare a data type for a variable name for e.g. 'int', and then assign something of that type. Variable x = 10 makes the variable x refer to the integer 10. Later, x = "hello world" makes the variable x  refer to a string containing "hello world". But in other programming languages you declare int x and then x = 10, but assigning x = "hello world" will give you a compile-time error.

  • Also, dynamically defining makes everything more unpredictable what a variable refers to.

  • Python is strongly typed. It means that if x = "10" will always remain a string, and never be coerced to a number if the program requires it. Every type of conversion in python must be done explicitly.

  • Python is object-oriented. Everything is an object.

  • Python mandates correct indentation of the code.

  •  Code Blocks are identified by the level of indentation. There is no control on braces in Python.

  • The code is compiled into byte code, then it is executed in a VM. This means that python code is platform-independent.

In this lab environment, you don't need to install python. You are already provided with the working environment. If you are working in Python then you may need to install it in your system. There are two modes in Python -

  • Interactive Mode: Python executes one command at a time also called Python Shell.

  • Script Mode: Saving the script in a file and then running the script. 

What is the Print() function?

  • This lab involves printing output to the console. The print() function is a way to print to the standard output.

  • print() can contain one or more comma-separated 'Objects' to be printed. Values must be enclosed within parentheses.

  • Example: If you want to print “Hello, World!”,  you will write it in the following way:

    • print("Hello, World!")

    • You get the output as:  Hello, World!

  • The quotation marks where the string begins and ends.

Lab Tasks:

  1. Using print() function to print Hello Whizlabs.

Join Whizlabs_Hands-On to Read the Rest of this Lab..and More!

Step 1 : Login to My-Account
Step 2 : Click on "Access Now" to view the course you have purchased
Step 3 : You will be taken to our Learn Management Solution (LMS) to access your Labs,Quiz and Video courses

Open Compiler