Skip to main content

Posts

Showing posts from April, 2018

DECISION MAKING STATEMENTS

DECISION MAKING STATEMENTS During the execution of the program, when there is a specific application to check the condition and make a proper decision, Decision making statements are used to anticipate specific actions which has to be taken depending upon the condition. Decision making statements are evaluated using TRUE and FALSE values. For example, if a particular condition is TRUE what outcome is expected and when, FALSE what outcome is expected. Depending on the application of program, set of statements are written into the code to perform a particular task. Python provides following types of decision making statements: Ø If statement: It is normal If statement which has condition in terms of Boolean expression, comparison operators, etc. Ø If..else statement: In this case, an If is followed by an else statement. It means ‘IF’ condition turns to be FALSE than ‘ELSE’ will be executed automatically Ø Ladder If.. else if .. else if: This is an extension o...

DATATYPE – TUPLES AND DICTIONARIES

DATATYPE – TUPLES AND DICTIONARIES PYTHON TUPLES In Python programming language, tuple is similar to that of list. The main difference between tuple and list is, elements of tuple cannot be changed once it is assigned and in list the element can be changed. This is called as immutable. Tuple can store sequence of data within it, which are separated by a comma and enclosed inside round brackets. Example: Tuple1 = (“A”, 21, 78, “Red”, 50, “Apple”) In this way a tuple is created, items inside the tuple are separated by a comma and string is always stored into double quote as explained earlier. Usually when there is multiple data stored inside an array, list, tuple, etc. the indexing of it starts from zero. For example Tuple1[0] = ‘A’ and it ends on n-1. There are many other ways of accessing items inside a tuple similar to that of list as explained in my videos. You can perform various arithmetic operations on tuple. Let see some more about Tuples in detail. ...

DATATYPE – PYTHON LISTS AND SLICING

DATATYPE – PYTHON LISTS AND SLICING Python lists are the most versatile and useful datatype. Lists can store a sequence of data within it, which are separated by comma and enclosed inside square brackets. The good feature of Python Lists is, the data or items stored can be of mixed data types like strings, integer, float, etc. which can be stored into a single sequence. Example: List1 = ["A", 21, 78, "Red", 50, "Apple"] In this way a list is created, items inside the list are separated by a comma and string is always stored into double quote as explained earlier. Usually when there is multiple data stored inside an array, list, tuple, etc. the indexing of it starts from zero. For example List1[0] = ‘A’ and it ends on n-1. There are many other ways of accessing items inside a list as explained in my video. You can perform addition of two or more lists. Lets see something more about Lists in detail. Some functions to be used with Lis...

BUILT INS FUNCTIONS IN PYTHON

BUILT INS FUNCTIONS IN PYTHON Every programming languages have certain pre-defined functions. Similarly, for certain tasks python has built in functions which you can access and understand as explained in the video.   dir(__builtins__): This module will return all the built in function and identifiers directly available to the programmer.   help(“function name”): This is the most important function in python. It gives the complete detail regarding the function which you mentioned inside help().

CREATE NEW PYTHON FILE .PY AND RUN IT

CREATE NEW PYTHON FILE .PY AND RUN IT Until now, we learned how to use python IDLE and make it interactive with user by understanding the concept of storing variables, taking input from user, type casting the input and few other data types’ concept. In this video I am going to explain how to create a new python .py file and run it. A bunch of code performing a certain task is to be written in python file. In this video, I have explained a basic code where two inputs are taken from the user and Arithmetic operations are performed respectively. The input taken from the user is type casted into an integer and used. Once you are done with the code, save the code and click on run or press F5 to run the program. If there is any error, you will get an error message else the code will run perfectly.

INPUT FROM USER AND STORE IT IN VARIABLE

INPUT FROM USER AND STORE IT IN VARIABLE We have discussed in the earlier videos and blogs regarding variables and multiple assignments. Now let’s move on with taking real time inputs from user and storing it in a variable. Name = input(“Enter the Name : ”) This function is used to ask real time data from users and store it in the variable defined as Name. This function takes the value in string. This means when you give input as a numeric value, it also considers it as a string input and you can access it as I have explained in the video. To consider this string as numeric value or integer, we need to type cast the taken input as shown. Age = int(input(“Enter your age :”)) This function will type cast your string into an integer value. Type Casting:   In simple words, it means conversion of data type. To make use of programming approach in day to day life, conversion of data type is very useful. As explained earlier input() function considers the value in stri...

DATATYPES- NUMBERS AND STRINGS

DATATYPES- NUMBERS AND STRINGS Data types: As mentioned earlier, particular byte is reserved in memory when a variable is declared. This memory location depends on the data types user defines. For example, a person’s name is a string and his age and income is a numeric value. Python has five standard data types: Ø Numbers Ø String Ø List Ø Tuple Ø Dictionary Python Numbers: This data type is used to store numeric value. For example: Age = 25 Income = 25000 Python has four different numeric types with examples are shown below: Ø Int (signed integer): 50, -68, 0x10, -0x250, etc. Ø Float(floating point real values): 13.2, 48.59, 6.0-E15, -85,etc. Ø Long(long integers, can be represented in octal and hexadecimal format): 9876L, -0x21L, 5425426L, etc. uppercase L symbol is used to display or represent long integer. Ø Complex( complex numbers): 12+51j, -87j, 8e+0j, etc. A complex number is usually represented in x+iy format, where x and y are re...

VARIABLES AND MULTIPLE ASSIGNMENTS

VARIABLES AND MULTIPLE ASSIGNMENTS Variables: Variables are reserved memory locations to store value. When a variable is created, some space is reserved into the memory. The assignment is done using the equal sign (=), example A=2(This expression means an integer 2 is saved in the variable A) Python interpreter allocates memory depending on the datatype which is used. There are many datatypes like integers, float, strings, etc. Every datatype has different bytes of location reserved into the memory. Let’s see some of the examples: Name = “Arnold” Here a string called Arnold is stored in variable called Name. Age= 25 Here an integer or a number doesn’t require single or double quote to define. Note: You cannot define variable name with space between two or more words Example: My name = “Jack” This will give an error Correction: MyName = “Jack” Multiple Assignments: Python allows user to assign single value to multiple variables simultaneously. For examp...

NUMBERS AND OPERATORS

NUMBERS AND OPERATORS Numbers are normal operand values which are used to perform set of task or operations using an operator. Numbers can be integers, decimal value, etc. There are many operators in Python. Some of them are listed below: Ø Arithmetic operators Ø Comparison operators Ø Logical operators Ø Bitwise operators Ø Assignment operators In this blog we will see about Arithmetic operators and understand how to use it with Python IDLE to perform certain calculations. PYTHON ARITHMETIC OPERATORS OPERATOR DESCRIPTION EXAMPLE Addition (+) Adds two values 5+6 = 11 Subtraction (-) Subtracts 5-3 = 2 Multiplication (*) Multiplies two values 4*8 = 32 Division (/) Divide by right hand operand 6/3 = 2 Modulus (%) Divides and gives the remainder 6%3 = 0 Exponential (**) Performs power calculations on operand 2**4 = 32 Dou...

INTRODUCTION TO PYTHON AND SOFTWARE INSTALLATION

INTRODUCTION TO PYTHON AND SOFTWARE INSTALLATION Introduction: Python is a very powerful programming language developed by Guido van Rossum during 1980’s. Python is an open source, high- level object oriented scripting programming language. Python is used by modern programmers because it is easy to learn and understand and at the same time very powerful. Python supports various other programming languages like Perl, PHP and so on. The main feature or advantage about python is, it is an interactive and interpreted programming language. Unlike other programming languages, like C, C++, JAVA, Python doesn’t need any compiler to run the code. The code can be directly written and run using the python software and hence it is an interpreter language. Python is derived from many other programming languages. It supports object-oriented style which means that the program can be encapsulated with objects. Some of the Features of Python are: 1)    It s...