Computer internally stores characters as numbers.
Every character has a unique Unicode value.
Ord
To find the Unicode value of a character, we use the
Code
Output
chr
To find the character with the given Unicode value, we use the
Code
Output
Unicode Ranges
48 - 57 -> Number Digits (0 - 9)
65 - 90 -> Capital Letters (A - Z)
97 - 122 -> Small Letters (a - z)
Rest -> Special Characters, Other Languages
Printing Characters
The below code will print the characters from
Code
Output
Comparing Strings
In Python, strings are compared considering unicode.
Code
Output
As unicode value of
Character by Character Comparison
In Python, String Comparison is done character by character.
Code
Output
Code
Output
Best Practices
Naming Variables Rule #1
Use only the below characters
- Capital Letters ( A – Z )
- Small Letters ( a – z )
- Digits ( 0 – 9 )
Underscore(_)
Examples:
age, total_bill
Naming Variables Rule #2
Below characters cannot be used
- Blanks ( )
- Commas ( , )
- Special Characters
( ~ ! @ # $ % ^ . ?, etc. )
Naming Variables Rule #3
Variable name must begin with
- Capital Letters ( A – Z )
- Small Letters ( a – z )
- Underscore( _ )
Naming Variables Rule #4
Cannot use Keywords, which are reserved for special meaning
- int
- str
- printetc.,
Keywords
Words which are reserved for special meaning
Code
Output
Case Styles
- Camel case: totalBill
- Pascal case: TotalBill
- Snake case: total_bill
Snake case is preferred for naming the variables in Python.