Site icon MiltonMarketing.com – Bernard Aybout's Blog

Learn Python Hello World Program

Learn Python Hello World Program

print is a function in Python 3, which uses parenthesis: Python 3.x: Python 2.x: print( hello ) print hello

Python is a very easy language and has a very straightforward syntax. It encourages programmers to program without boilerplate (prepared) code. The simplest directive in Python is the “print” directive – it simply prints out a line (and also includes a newline, unlike in C).

There are two major Python versions, Python 2 and Python 3. Python 2 and 3 are quite different. This tutorial uses Python 3, because it more semantically correct and supports newer features. Lastly, Python 2 will slowly get phased out.

For example, one difference between Python 2 and 3 is the

print

statement. In Python 2, the “print” statement is not a function, and therefore it is invoked without parentheses. However, in Python 3, it is a function, and must be invoked with parentheses.

To print a string in Python 3, just write:

[python] print("This line will be printed.")[/python]

Python Hello World Program

Python Indentation

Python uses indentation for blocks, instead of curly braces. Both tabs and spaces are supported, but the standard indentation requires standard Python code to use four spaces. For example:

[python] x = 3
if x == 3:
# indented four spaces
print("x is 3.")[/python]

Change the value of the variable from 3 to another number. example: x = 9 so when the if x == 3: statement is executed it will be false (so nothing will print on the screen.) because x=9 not 3, after your change. Play with the code below:

 

Related Videos:

Related Posts:

Introduction to Python Programming Language

Learn about Numpy Arrays in Python programming

Learn Partial functions Python programming

Python Basic Operators

Learn Python Lists

Learn Partial functions Python programming

Learn Multiple Function Arguments in Python

Learn about programming Loops in Python

Learn List Comprehensions in Python Programming

Comparing Python to other languages

Why Python is the cooler programming language

Learn about Python Generators

Learn about programming Functions in Python

Python String Formatting

Object-Oriented Programming (OOP)

Learn about programming Classes and Objects in Python

 

Exit mobile version