Lecture 2 – R & Python
Nirma University, MBA FT, July-Sep, 2020
[email protected]Tokens
• Keywords
• Identifiers / Variables
• Operators
• Delimiters
• Literals
Literals
• 78
• 21.98
• ‘Q’
• “Hello”
• ‘Hello World’
• type(‘Hello World’)
• type(123)
Keywords
• and
• class
• Else
• If
• Elif
• Break
• Continue and more …
Operators
• + - * / // % ** - Arithmetic operators
• == != >= <= - Relational operators
• And not or – Logical operators
• & | - Bitwise operators
Delimiters
• () {} []
• ,:.‘=;
• Etc.
Identifiers / Variables
• Starts with _ or letter of lower case / upper case with any length
• Cannot start with digit or keyword
Core Data Types
• integer – 10, 20, 25, 32, -9, etc.
• int(12.456)
• int(‘125’)
• 3.7e1 – Float
• 3.7 – Float
• Float(‘10.23’)
• 2+4j – Complex number
• type(True)
• D = ‘Hello World’
• D
• ABC = ‘12.5’
• str (ABC)
print
• print(“We are at NU, \” MBA FT \” “)
• Print(‘Hello ‘, ‘ ‘)
• Print(‘World’)
Assignment operator
• P = Q = R = 100
• P=Q+1
•P
input
• str1 = input(‘Enter String1: ‘)
• Str2 = input(‘Enter String2: ‘)
• Print(‘ String1 = ‘, Str1)
• Print(‘ String2 = ‘, Str2)
eval
• A=2
• B=3
• X = eval(‘A+B’)
• X
• Age = eval(input(‘Enter Age: ‘))
• print(Age)
• Age = eval('print("Hello")')
• print(Age)
Formatting float
• Print(format(10.345, “10.2f”))
• Print(format(10, “10.2f”))
• Print(format(10.32245, “10.2f”))
abs
• abs(-2)
• abs(4)
ASCII values
• Ord(‘A’)
• Ord(‘Z’)
• Ord(‘a’)
• Chr(90)
• Chr(65)
• Chr(122)
Thank you – [email protected]