String Slicing
Obtaining a part of a string is called string slicing.
Code
PYTHON
- Start from the start_indexand stops atend_index
- end_indexis not included in the slice.
Code
PYTHON
Output
Slicing to End
If end index is not specified, slicing stops at the end of the string.
Code
PYTHON
Output
Slicing from Start
If start index is not specified, slicing starts from the index 0.
Code
PYTHON
Output
Checking Data Type
Check the datatype of the variable or value using
type()
Printing Data Type
Code
PYTHON
Output
Type Conversion
Converting the value of one data type to another data type is called Type Conversion or Type Casting. We can convert
- String to Integer
- Integer to Float
- Float to String and so on.
String to Integer
int()
converts valid data of any type to integerCode
PYTHON
Output
Invalid Integer Conversion
Code
PYTHON
Output
Code
PYTHON
Output
Adding Two Numbers
Code
PYTHON
Input
Output
Integer to String
str()
converts data of any type to a string.Code
PYTHON
Input
Output
Summary
- int()-> Converts to integer data type
- float()-> Converts to float data type
- str()-> Converts to string data type
- bool()-> Converts to boolean data type