Python For Beginner's Day - 5
-> Numeric Data Types Conversion:
Conversion is possible using int(), float() and complex() methods, but complex numbers cannot be converted to another number type.
-> Casting:
Casting can be done using constructor functions, int(), float() and str().
-> Booleans:
Any expression can be evaluated and returns either True or false.
bool() function will evaluate any value, and returns any of the value.
Some values are always false, the empty values like (), [], {}, "", 0 and None.
-> Strings:
Strings can be represented by using Single quotes(' ') or double quotes(" ").
Multiline Strings can be represented using 3 Single Quotes or 3 double quotes.
Strings are similar to Arrays, square brackets([]) can be used to access the elements of the string.
To get the length of the string, use len() function.
To check if particular word or character is present in the string, use keyword 'in'
and to check if it is not present in the string, use 'not in'
-> Slicing:
It's used to return the part of the string using 'a:b' , here a is the start index and b is the end index(which is not included) and the index starts from 0.
Slice from start will start from first character, by leaving start index,
Slice to the end will go to the end, by leaving end index,
Use Negative Indexing, to start the slice from end of the string,
-> Modify Strings:
upper() method returns the string in Upper Case.
lower() method returns the string in Lower Case.
strip() method is used to remove the whitespaces at the beginning and/or at the end.
replace() method is used to replace a string with another string.
split() method returns a list where the text between the specified separator becomes the list items.
Concatenation is used to combine 2 strings using + operator.
But to combine string and an integer, we can't use + operator instead we can use format() method.
format() method is used to specify the string as f-string, and add curly brackets{} as placeholders.
The placeholder can contain variables, modifiers, operations and functions to format the value.