0% found this document useful (0 votes)
5 views5 pages

Python Notes

The document outlines key concepts of Python programming, including the importance of indentation and variable naming rules. It explains that variables are created upon assignment, are case-sensitive, and must follow specific naming conventions. Additionally, it covers comments, type casting, and built-in data types in Python.

Uploaded by

shopeecrawl0001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Python Notes

The document outlines key concepts of Python programming, including the importance of indentation and variable naming rules. It explains that variables are created upon assignment, are case-sensitive, and must follow specific naming conventions. Additionally, it covers comments, type casting, and built-in data types in Python.

Uploaded by

shopeecrawl0001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Indentation

 Python will give you an error if you skip the indentation

 The number of spaces is up to you as a programmer, the most common use is four, but it has
to be at least one.
 You have to use the same number of spaces in the same block of code, otherwise Python will
give you an error

Python Variables
 Python has no command for declaring a variable.
 In Python, variables are created when you assign a value to it:

 Variable names are case-sensitive.

Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume). Rules for Python variables:

 A variable name must start with a letter or the underscore character


 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and
_)
 Variable names are case-sensitive (age, Age and AGE are three different variables)
 A variable name cannot be any of the Python keywords.
 Multi Words Variable Names:
Camel Case myVariableName = "John"
Pascal Case MyVariableName = "John"
Snake Case my_variable_name = "John"
 Many Values to Multiple Variables

 One Value to Multiple Variables

 Unpack a Collection

Comments
 Comments start with a #
 Python does not really have a syntax for multiline comments. To add a
multiline comment you could insert a # for each line.

 Or, not quite as intended, you can use a multiline string.

Casting
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0

Get the Type


x=5
y = "John"
print(type(x))
print(type(y))
Python Data Types:
Built-in Data Types:
Setting the Data Type

Setting the Specific Data Type

You might also like