First Python Program

First Program
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

print("Hello Universe")                  
Output:    

Hello Universe

  

Python Identifiers

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 

if True :                                                             
      
print ("True")                                          

else:                                                                 
     
print ("False
")                                                 


However, the following block generates an error(because of wrong indentation)-

if True:                                
     
print ("True
")

else:
     print ("False
")        
                   
Thus, in Python all the continuous lines indented with the same number of spaces would form a block. The following example has various statement blocks.


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

The statements contained within the [], {}, or () brackets do not need to use the line continuation character. For example-

days = ['Monday', 'Tuesday',                 'Wednesday', 'Thursday','Friday']     

Quotation in Python

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

word = 'word'                              

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.

#
This is a comment, too.

#
This is a comment,too.          

#
I said that already.ok

Another Way To print

Execute this code to print string.

import sys   
          

x = "your string"                 

sys.out.write(x)

Practice Time

Q1. Write a program to print "Hello Universe" without print statement.

Q2. Wrte a program to print -
       "Hi I am Alien
        I am learning Machine language 
        So that I could talk with machine".

Post a Comment

0 Comments