First Program |
Let's understand what python and what is programing
Python is language to communicate with computers it help us to tell computers what to do, when how to do, how to do where to do etc... all these kind of instructions we can provide to computers using python programing language.
We call it programing language because when we make program we write some code and after writing everything about we save it as a file with one specific extension, that file contain our set of instructions is computer program.
Let's create a very very simple program called Hello Universe.A "Hello, Universe!"is a simple program that outputs Hello, Universe!on the screen.Since it's a very simple program, it's often used to introduce a new programming language to beginners.
Type the following code in any text editor or an IDE and save it as hello_Universe.py
Output:
Hello Universe
A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $, and % within identifiers.
Python is a case sensitive programming language. Thus, Manpower and manpower are
two different identifiers in Python.
Here are naming conventions for Python identifiers-
1. Class names start with an uppercase letter. All other identifiers start with a
lowercase letter.
2. Starting an identifier with a single leading underscore indicates that the identifier is private.
3. Starting an identifier with two leading underscores indicates a strong private identifier.
4. If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Lines and Indentation
Python does not use braces({}) to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation, which is rigidly enforced.
The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount. For example-
Note : In 2nd, 4th line there are 4 spaces before print statement
print ("True")
else:
print ("False")
However, the following block generates an error(because of wrong indentation)-
print ("True")
else:
print ("False")
Multi-Line Statements
Statements in Python typically end with a new line. Python, however, allows the use of the line continuation character (\) to denote that the line should continue. For example-
total = item_one + \ item_two + \
item_three
Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string.
The triple quotes are used to span the string across multiple lines. For example, all the following are legal
sentence = "This is sentence."
paragraph = """This is a paragraph. It is
made up of multiple lines."""
Comments in Python
A hash sign (#) that is not inside a string literal is the beginning of a comment. All
characters after the #, up to the end of the physical line, are part of the comment and the Python interpreter ignores them.
#Python Program(This is first comment)
print("Hello Universe") #output:Hello Universe("2nd Comment)
Python does not have multiple-line commenting feature. You have to comment each line individually as follows-
# This is a comment, too.
# This is a comment,too.
# I said that already.ok
Another Way To print
x = "your string"
sys.out.write(x)
0 Comments