Skip to main content

Posts

Showing posts with the label Index in python

DATA TYPES IN PYTHON | (Numeric,Boolean, Dictionary)

Previous Variables in Python  In python programming language everything is an object and data type tells us which types of value the object is. Data types are classified into five types in Python programming language, they are:- Best Laptop for Web Development  in 2021. NUMERIC DATATYPES BOOLEAN DATATYPES DICTIONARY SEQUENCE DATATYPE SET type() method  Type method is used to know what type of data we are using. Numeric Data Types Numeric type consists of numerical value data types for example whenever we assign a decimal value or numbers to variables then it comes under numeric data types. It contains : int float complex type Int or Integer It is a data type where the value given by the user can be positive or negative and can be of any length that means it can be a big integer or small integer but it should not be a fraction or a decimal value. #Python Program to # demonstrate int value p= 5556677 print ( type (p)) q=- 45 print ( type (q)) #output < class 'int' >...

Even or Odd Number and Factorial of a Number in Python Programming

1. To Check if the given number is even or odd If a number is completely divided by 2 then it is even number. When the number is divided by 2, we use the remainder operator %  to calculate the remainder. If the remainder is not zero, the number is odd. SOURCE CODE:- n= int ( input ( "enter any number:- " )) if (n% 2 == 0 ): print (n , 'is even number' ) else : print (n , 'is odd number' ) OUTPUT 1st Run enter any number:- 2 2 is even number 2nd Run enter any number:- 3 3 is odd number In the above code we use "Simple if" statement.  In the above program, we ask the user for input and check if the number is odd or even. 2.Factorial number Factorial of a number defined as the product of all numbers from 1 to given number. For example  5!(5 factorial)=5*4*3*2*1 is 120. Note = factorial of 0 is 1 SOURCE CODE n= int ( input ( "Enter any number:- " )) fact= 1 for i in range ( 1 , n+ 1 ): fact=fact*i print ( 'factorial of' , ...

BIT-WISE OPERATORS

  Bitwise operators BITWISE OPERATOR:   BITWISE Operator in python are used to perform bitwise calculations on numbers (integers) Ø   The name itself suggests that something to do with binary format like bits. Ø   We cannot directly perform operations on integers so we need to convert them into binary format and then we need to do. Ø   Result will be in decimal format. Types of bitwise operators: Ø   Bitwise And - & Ø   Bitwise OR - | Ø   Bitwise NOT - ~ Ø   Bitwise xOR - ^ Ø   Bitwise right shift - >> Ø   Bitwise left shift - << 1.   Bitwise AND (&):   this operator returns 1 if both the values are 1 or else it returns 0           x        y       x&y    1       1         1    1     ...

Number System in Python

  Python generally supports integers, fractional values and complex numbers and we have data types for them like int for integers, float for fractional values, and complex for complex numbers, we can understand that but if our computer wants to perform certain operations on bits or some other operations then we need to convert them into some number systems like binary, octal, hexadecimal. These are the three different number systems. Number conversions are used in programming languages because we cannot directly use some operators like bit-wise operators, we need to convert decimals into binary and sometimes we need to convert binary format of a number to decimal, so we use number conversions there Actually, number conversions are done on 4 types 1.       Decimal 2.       Binary 3.       Octal 4.       Hexadecimal 1. Decimal to binary:      ...

Index in Python

  Generally, we add elements in lists, tuples and we delete items, insert elements etc but how can we do that, how can we access a particular element, this is done by using index number. PDF FOR  INDEX IN PYTHON   Ø   Index numbers are nothing but numbers which are given to elements in a list or tuple or array etc to access them. Ø   Index number starts with zero and ends with one less than the given number but For example  List = [1,5,8,13,24,31] 0  1  2  3   4   5 Ø   Each index refers to one element, as we know here the elements in the list are 6 but the maximum index will be 5 this is because index starts with zero so maximum index will always be one less than the length of list or tuple or array etc. ADVANTAGES in Python: Ø   It makes our work easier like we can easily delete the element we want to delete by just using its index number. Ø   There are lot of ways to print elements using ind...

Contact form

Name

Email *

Message *