SYNTAX & BASICS
-
When we give a computer a set of instructions, we say that we're programming it.
-
Syntax : Syntax mean a set of rules to be followed while writing the instructions.
-
Variable : Variable is a named storage container (memory location) used to hold values while executing the program. For eg- a=5, here a is a variable holding 5 as value.
-
Identifier: Identifiers are the name given to elements to be used in program such as variable, functions, modules etc. Identifiers must begin with an alphabet (A-Z) or underscore(_), can contain digits(0-9) and should not contain space or any other special character.
-
Data Type: It holds the type of value a variable holds and what type of operations can be performed on it. For eg.- Maths operations (like +, -) cannot be performed on a textual value.
Following are the categories of data types in python:-
Text - str example: "Delhi", 'F-10B'. They are enclosed in quotes.
-
Numeric - int, float, complex example: 56, -96.51, 2+3i respectively.
-
Sequence - list, tuple example: [2,5,8], (34,89,7) respectively.
-
Mapping - Dictionary example: {"Rno":12,"Name":"Pihu"}
-
-
Functions: Functions are collection of statements grouped under a name and code is executed only when function is called. Certain values can be passed as parameters while calling them.
-
Built-in functions: They are ready to use functions which provide great ease into doing a complex job. example : len("Python") will return 6 (no. of characters).
-
User defined: They are defined by the programmer. They are made using def statement.
-
Handling Input and Output
Python print()
Used to display provided data on the screen.
print() parameters:
-
sep - Used to separate the objects while printing. Default is space(' ' ).
-
end - It is printed at the last. Default is new line ('\n').
Python input()
Used to prompt user to enter value. By default, it will accept string value.
int() function is used convert the string input into integer so that arithmetic operations can be performed.
Code
Output
Code
Output
Try It Yourself
Problem Statement 1 - Input user's name and hobby, then display welcome message along with his/her name and Hobby.
Ex. Input from user : Aryan and Football
Expected output : Welcome Aryan, you like to play Football
Problem Statement 2 - Input state and its capital and display with '@' symbol in between them.