For the sake of simplicity, I am dividing this into 3 parts:
Unlike other programming languages like c, cpp and java ,you don’t need to declare the type of a variable explicitly. This feature is called Dynamic Typing.
in C,
int a = 6;
here, the variable is declared as integer.
but in Python,
a = 6
and the variable a can be redeclared as
a = "hello world"
?️NOTE:
Variable names are case-sensitive., so a and A are considered different variables.
a = 6 #valid _a = 6 #valid -a = 6 #invalid
a = 5 b = 6 a + b #11 print(_) #11
a, b, c = 5, 6, 7
global x def print(): return x #there will be no error
PI=3.14
The print() function is a built-in Python function used to display output to the console.
a=10000 print("hello world") #hello world print("hello", "world")#hello world print("hello world",a) #hello world 10000
In print function, there are two main parameters.
example:
print("hello world") print("hi") # hello world # hi
print("hello", "world", sep="-", end = " ") print("hi") # hello-world hi
for the complete documentation of print, click here
print("hello\nworld") #hello #world print("hello\tworld") #hello world print("happy\trecking")#happy\trecking
x = 5 y = 10 print(f"x: {x}, y: {y}") # x: 5, y: 10
The input() function in Python is used to take user input from the console.
int a = 6;
?️NOTE:
By default, input() returns a string, so if you need to use the input as a different type (e.g., int, float), you need to convert it.
a = 6
In the upcoming blog, we'll delve into Python operators and conditional statements. Happy Learning???
The above is the detailed content of Day Mastering the Basics of Python. For more information, please follow other related articles on the PHP Chinese website!