Table of contents
- STARTING JOURNY FROM TWITTER NOW ON HASNODE :
- IDE VS COMPILER
- 2.VORTEX OF VARIABLES
- 3. DATA TYPES :
- 4. LEARNT 'INPUT' STAEMENT AND MERGED WITH IT 'PRINT' STATEMENT
- 5.ACCIDENTAL PROJECT
- 6. DATA TYPE AND THEIR TYPE CONVERSION AND THE MAJOR ISSUE THAT I FACED :
- 7. OPERATORS AND EXPRESSION
- 8.SOME MORE ABOUT STRINGS
STARTING JOURNY FROM TWITTER NOW ON HASNODE :
HI EVERYONE I AM ANISH CURRENTLY A STUDENT ,, ON A JOURNY LEARING ABOUT MY FAVOURITE BLACK BOX AI !!!
TILL NOW EVERYTHING SEEMS SMOOTH .
LEARNT ABOUT MANY THINGS THIS WEEK THAT IS SHARED BELOW :
IDE VS COMPILER
2.VORTEX OF VARIABLES
3. DATA TYPES :
Data types specify the type of data that a variable can hold. Here are some fundamental data types in Python along with examples:
Integer (
int
): It represents whole numbers, positive or negative, without any decimal points.x = 5 y = -15
Float (
float
): It represents floating-point numbers, which include decimal points.I = 3.14 temperature = 98.6
String (
str
): It represents a sequence of characters enclosed within single quotes, double quotes, or triple quotes.name = 'Alice' message = "Hello, world!"
Boolean (
bool
): It represents Boolean valuesTrue
orFalse
, used for logical operations.d = True h = False
List (
list
): It represents an ordered and mutable collection of items enclosed within square brackets.s = [1, 2, 3, 4, 5] names = ['Alice', 'Bob', 'Charlie'] print(names[0]) #prints : Alice
None Type (None
): It represents the absence of a value or a null value in Python.
result = None
4. LEARNT 'INPUT' STAEMENT AND MERGED WITH IT 'PRINT' STATEMENT
w1 = input() #1st input = 10
w2 = input() #2nd input = 20
print(w1 + w2) #o/p: 1020 why???????
\>>>In Python, theinput()
function always returns a string. So, when you input integers into w1
and w2
, they are treated as strings, not as integers. When you use the +
operator with strings, it concatenates them together instead of performing addition.<<<
5.ACCIDENTAL PROJECT
-:FIND (N^2):-
n=float(input('give a number:'))
print(n*n)
6. DATA TYPE AND THEIR TYPE CONVERSION AND THE MAJOR ISSUE THAT I FACED :
and some little info :
7. OPERATORS AND EXPRESSION
In Python, operators and expressions play crucial roles in performing operations on data. They are fundamental components used to manipulate values and variables.
Operators:
Operators in Python are symbols or special keywords that perform operations on operands .There are various types of operators in Python:
Arithmetic Operators: These operators perform arithmetic operations like addition, subtraction, multiplication, division, etc.
print('addition' , 5+2) print('subtraction' , 5-2) print('multiplication' , 5*2) print('division' , 5/2) #factorial quotient print ( 'floor division' , 5//2) #floordevidion :it will remove the decimal part of the quotient print('modulus' , 5%2) #will give remainder print('exponential' , 5**2) #5^2
Relational/comparison Operators: These operators compare two values and return a Boolean result (True or False).
#RELATIONAL OPERATORS ( > < >= <= == !=) ; output of relational operators is always boolean print(5>10) print(5<10) print(5>5) print(5>=5) print(5==50) print(5==5) print(5!=50) print(5!=5)
Logical Operators: These operators perform logical operations like AND, OR, NOT.
#LOGICAL OPERATORS ( and, or, not) ;output of logical operators are always Boolean print(True and True) print(True and False) print(False and True) print(False and False) print(True or True) print(True or False) print(False or True) print(False or False) print(not(True)) print(not False)
Expressions:
An expression is a combination of variables, values, operators, and function calls that evaluates to a single value. It can be as simple as a single variable or as complex as a combination of multiple operations.
Simple Expression:
x = 5 y = 2 * x + 3 # Expression involving multiplication and addition
Complex Expression:
a = 10 b = 20 result = (a * b) + (b / a) # Complex expression with multiple operations.
Expressions can contain operators that act as the "handlers" or instructions for performing specific operations on the operands (values or variables). The operators dictate how the expression should be evaluated.
In summary, operators are the symbols or keywords that carry out operations, while expressions are combinations of these operators and operands that result in a single value when evaluated.
8.SOME MORE ABOUT STRINGS
s='anishbhattacharya'
h='agnivbhattacharya'
a) INDEXING:
print(s[0]) #indexing
print(h[1]) #indexing
print(s[0]+h[1]) #concatenation
OUTPUT-- a
g
ag
a='0123456789'
b='0123456789'
print(a[0],type(a[0]))
print(b[1],type(b[1]))
print(a[4]+b[5]) #concatenation
print(int(a[4])+int(b[5])) #addition ; if you want to add the proper integer string then store them in integer(datatype) variable.
OUTPUT-- 0
<class 'str'> 1
<class 'str'> 45
b) SLICING:
#sclicing
l='0123456789'
print(l[-3:]) # o/p : 789
print(l[:2]) # o/p : 012
print(l[0:9]) #it goes from 0 to 8 th position #o/p : 012345678
print(s[0:2])
print(l[3:7]) #it goes from 3 to 6 th position #o/p : 3456
##In Python slicing syntax, when you omit the end index after the colon (:
), it implies that you want to slice until the end of the sequence and when you omit the start index after the colon (:
), it implies that you want to slice from index 0 till the end of the sequence.
d) COMPARISON BETWEEN STRINGS :
example1 : print('apple'>'one') #output: False
When we use comparison operator with strengths, it works differently. It will. compare the string character by character. Here the first letter of Apple is A, which is being compared with the 1st letter O of the. O of the word one. as a comes before O, so it cannot be greater than the letter O. Hence, it gives the output as false.
example2: print('four'<'ten') #out: True
example3: print('abcdef'<'abcde') #out: false
print('abcdef'>'abcde') #out: false
[Letter F on the left side has no letter left on the right side to be compared with Therefore, F cannot be smaller than nothing, hence it is false]
TO SUMUP {The comparison doesn't consider the lengths of the strings or the number of characters unless all characters from the beginning to the differing character(s) are the same. If the first characters of both strings are equal, the comparison proceeds to the next character in each string, continuing until a difference is found or until one string ends.}