As we all know and believe too python to one of the popular and highly learned, preferred programming language because of its simplicity, even though its slow from rest of the others and because of its simplicity its has become lingua franca.
BASIC FUNDAMENTALS
A fundamental way for computers to differentiate different types of data using specific keywords.
To represent numbers, to represent different types of numbers, to represent numbers more than 32 digit and etc.
Conditionals
Decision making is one key aspect for every one of us in different types of their situation, in the same computers can be also allowed to make decision accurately by the developers. When faced with cases.
Anyone can help computers in making decisions by knowing the decision-making principles of computers language.
• Simple if statements: To make easy decisions.
• If-else: To choose between any two choices of decision and to make the one which satisfies the need.
• If-elif-else chain: Situations where more than two choices are possible but only one choice is needed to made. EX – greatest number among three.
• Multiple elif Blocks: Critical situations where computer are provided with several choices, it may be five or more than that and computers needs to decide according to condition.
Ex: The Tic tac toe decision making.
Looping
The smart way of saving time and stop doing redundant task is to make computers follow instructions and get the work done using looping.
Common types of loops
• For loop- The type of loop which iterates over the sequences of object, sequence are ordered collection of pairs.
• While loop – The loop which works on Conditionals, terminates when the condition fails.
Break and Continue Keywords: There are two special keywords used in loops for breaking down infinite loops.
Break statements: stop execution, read and execute no more line and exit immediately from the loop.
Continue statements: Skip any further lines to execute and pass control back to the beginning of the loop.
Range: Function generates sequence of numbers with starting default value as 0 and terminating at mentioned limit.
for value in range(5):#starting with default value of 0 up to 5
print(value\t)
for value in range(1,10):#starting with default value as 1 upto 10
print(value)
Functions
Functions are blocks of codes consisting (variables, conditionals, loops, etc.) to accomplish different objective in a program, to perform specific task of the program.
Functions are categorized into Library functions(built-in) and as User-defined (Customized functions), Library functions are built-in functions which are already created and can be used in program, whereas user-defined functions are yet to be created to fulfil the different need of the program accordingly.
Function creation: In python function are created using def keyword followed by the name of the function, arguments in brackets and with a semicolon which indicates the end of the function header and start of the function definition with indentation in new line.
def compute(x,y):
sum=x+y;
print(sum)
function definition.
Types of Arguments
1.Positional arguments:Argument in which python matches every
argument.
2.Keyword arguments:The type of arguments in python in which
you directly associate variable with value, these arguments
don't require ordering.
3.Default arguments:The values of the arguments which are
mentioned previously.
4.Arbitrary Number of arguments:The type of argument in which
the any no. of arguments can be passed,
syntax: def(*parameters)
The function definition to run, we need to call the function which is called calling of the function.
Return statement: The return statement reads in the function definition exit the function and returns back to the from where the function was called.
Example of return statement;
def check_state(num):
if num>0:
return num
elif num=0:
return num
else:
return num
That's all, Thanks for reading I hope it was informative and easy to grasp tutorial to get started with python. From next tutorials we will focus on implementation.
Resources
Book:https://images-na.ssl-images-amazon.com/images/I/51Z6Vf5UwTL._SX376_BO1,204,203,200_.jpg
Youtube:https://www.youtube.com/playlist?list=PLEbhahwkhw6x5-apCoE5Qf3M_gR0hhApJ
Top comments (0)