Unicode
Unicode provides a unique number for every character, no matter what the platform,no matter what the program,no matter what the language.
In Python 2, two types are used to represent strings.
str - was a “byte string” type; it represented a sequence of bytes in some particular text encoding, and defaulted to ASCII.
stringtype = 'This is string.'
Unicode - Unicode string type.
unicodetype = u'This is unicode string'
In Python 3, there is one and only one string type.
str - It is used as a string and unicode.
Example:
Python2:
>>> s = '\u0026' #simple string
>>> s
'\\u0026'
>>> s = u'\u0026’ #unicode
>>> s
u'&'
But in python3 we don’t need to write ‘u’ before the string
>>> s = '\u0026'
>>> s
'&'
Check with emoji (not supported in py2)
2.0
>>> x = u"i ♥ python"
>>> x
u'i \u2665 python'
>>> x = 'i \u2665 python'
>>> x
'i \\u2665 python'
3.0
>>> x = 'i ♥ python'
>>> x
'i ♥ python'
>>> x = 'i \u2665 python'
>>> x
'i ♥ python'
Unicode in variable and function names.
# python 3: create one file and write below code and run it from terminal
def Ω(n):
return n + 1
ã = 4
print(Ω(ã))
Selective/Conditional:
- if<condition>
- if<cond>...elif<cond>..else
- if<cond>...elif<cond>..elif<cond>..elseIterative
- for
- whileTransfer
- break
- continue
- pass
Before start with control flow statement we need to learn about
Indentation/Indent
By default 4 spaces indentation is present(We are doing programing from the terminal that’s why we need to manually add indentation).If you want to change it we can.
>>> if 5 > 4:
... print("dd")
...
>>> if 5 > 4:
... print("ss")
File "<stdin>", line 2
print("ss")
^
IndentationError: expected an indented block