Introduction to Python Commands
Python is known as a high-level, interpreted and object-oriented programming language. It was developed by Guido van Rossum. Python is easy to learn, easy to use and maintain, portable, extendable scalable, GUI programming. Python can be used as a scripting language. It supports automatic garbage collection, provides the high-level dynamic type and dynamic type checking. Python has the list of commands which is used while doing the programming for the same.
Basic Python Commands
- Comments: # symbol is being used for comments in python. For multiline comments, you have to use “”” symbols or enclosing the comment in the “”” symbol.
print “Hello World” # this is the comment section.
“”” This is Hello world project.”””
- Type function: This Python Commands are used to check the type of variable and used inbuilt functions to check.
type (20), its type is int.
>>> type (20) < type ‘int’ >
type (-1 +j), its type is complex
>>> type (-1+j)
< type ‘complex’ >
- Strings: It is mainly enclosed in double quotes.
type (“hello World”), type is string
>>> type (“hello World”)
< type ‘str’ >
- Lists: Lists are mainly enclosed in square bracket.
type ( [ 1, 2 ] ), type is list
>>> type ( [ 1, 2, 3 ] )
< type ‘List’ >
- Tuple: Tuple are mainly enclosed in parenthesis.
type ( 1, 2, 3), a type is a tuple.
>>> type ( ( 1, 2, 3) )
<type ‘tuple’ >
4.8 (2,902 ratings)
- Range: This function is used to create the list of integers.
>>> range ( 10 )
Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range (1,10)
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
- Boolean values: This data type helps in retrieving the data in True or false form.
>>> type (True)
< type ‘bool’ >
>>> type (False)
< type ‘bool’ >
- Operator: Different operator are used for the different functions like division, multiply, addition and subtraction.
>>> 2 * * ½
- Variable and assignment: The assignment statement has variable = expression. Single ‘=’ is used for assignment and double ‘= =’ is used to test for quality.
>>> X= 235
>>> print X
>>> Z= 2* X
>>> print Z
- Comparison operators: To compare the two values and result of comparison is always boolean value.
>>> 2 < 3
Intermediate Python Commands
- Conditional/ decisions: It is used to make out the decision between two or more values like if-else
Print “Hello, world”
Print “Hello, world in Else”
- For Loop: This Python Commands is used when there is iteration and action consists of the same elements.
for x in [ 1, 2, 3, 4, 5, 6]:
- While loop: While loop will never be executed, if the condition evaluates to false for the first time.
- Else in loop: Loop have optional else for execution.
for x in [ 1, 3, 5, 7, 9, 11]:
Print “In Else”
- Break, continue statement: Break statement is used to exit out the loop when particular output is achieved, continue is used to continue with next iteration of a loop.
Print “X is 0”
Print “X is greater than 0”
- Lists: It is the finite number of items, and by assigning a value to list the list value will get changed.
>>> a = [1, “JAY”, 34] >>> a  1
>>> a  = 101
[101, “JAY”, 34]
- Length of list: To know the length if list.
>>> X = [1, 4, 67,9] >>> len (X)
- Sublists: It will give you the values between the mentioned start index and the end index.
x [start : end] >>> X [1, 3, 4,6, 7, 8, 9, 0, 2] >>> X [2:5] [4, 6, 7]
- Joining two list: + operator is being used to concatenate 2 lists.
>>> [2, 1, 5] + [0, 4,6,7] [2, 1, 5, 0, 4, 6,7]
- Strings: It is used to check the index to know the character written in string.
>>> x= “hello, world”
>>> x  ‘l’
>>> x  ‘o’
Advanced Python Commands
- List methods: The different methods available to in list to perform the function.
X [1, 2,3,4,5]
- >>> X.append (7)
[1, 2, 3, 4, 5, 7]
- >>>X.insert (0, 0)
[0, 1, 2, 3, 4, 5]
- >>> X.remove (2)
[0, 1, 3, 4, 5]
- >>> X.pop (1)
Tips And Tricks to use Python Commands
- Use data type set which is inbuilt function in python for the lists.
- Use the enumerate function to iterate the object.
- Use dynamic typing.
- Use operators while comparing the values.
- Use conditional expressions for better result.
- Use modules to make the programs separate and reusable.
Python commands are easy to use, easy to write and easy to learn. It is very versatile and helps in achieving the result in different ways. Python is one of the most used languages in automation nowadays as it is diverse and well-developed language. The above commands help you in getting the brief idea about the uses of python commands and how it can be used.
Python commands should be well managed and well written to get good performance. Python is a widely used language and has a large community to support. It has a good career at present and in future as well in IT industry. The one can learn python commands easily as it is simple and straight forward for the one who knows object-oriented programming. The organizations are demanding python at a higher level as well to accomplish their targets and people are earning really good in this expertise.
This has been a guide to Python Commands. Here we have discussed basic as well as advanced Python Commands and some immediate Python Commands. You may also look at the following article to learn more-