0% found this document useful (0 votes)
43 views11 pages

Python Programming

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Key concepts in Python include namespaces, scope, and naming conventions like snake_case. Namespaces allow unique naming to prevent conflicts, and scopes determine where names are visible. Well-written code is readable, solves users' problems, and requires skills like collaboration in addition to technical skills that evolve over time.

Uploaded by

Srinivasa Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
43 views11 pages

Python Programming

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Key concepts in Python include namespaces, scope, and naming conventions like snake_case. Namespaces allow unique naming to prevent conflicts, and scopes determine where names are visible. Well-written code is readable, solves users' problems, and requires skills like collaboration in addition to technical skills that evolve over time.

Uploaded by

Srinivasa Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 11

Python Programming

(774) Python for Diploma Qualifier - YouTube

https://www.programiz.com/python-programming

https://www.freecodecamp.org/

https://youtu.be/3j_CcqRljsg?t=62

https://www.sitepoint.com/how-to-write-good-code/?
utm_source=newsletter&utm_medium=email&utm_campaign=whats_the_best_programming_language_to_learn_first&ut
m_term=2022-05-14

https://docs.python.org/3/tutorial/

Python keywords are special reserved words that have specific meanings and purposes and can't be used for
anything but those specific purposes. These keywords are always available—you'll never have to import them into
your code. Python keywords are different from Python's built-in functions and types.
A code block (body of a function, loop, etc.) starts with indentation and ends with the first unindented line. The
amount of indentation is up to you, but it must be consistent throughout that block.

Here are the naming conventions you’ll see most often in development:
Camel case: Camelcase is a naming convention for writing file or object names using compounded or joined words
with at least of those words beginning in a capital letter. Camelcase is used in programming language to name
different files and functions without violating the naming laws of the underlying language.Variable names are
written in a series of words that are joined together, with each word except the first beginning with a capital letter.
Example: firstName, lastName, printFullName(). CamelCase is used in most modern programming languages,
including several popular languages such as C, C++, Visual Basic (VB), and JavaScript to name just a few. Java
uses CamelCase as a practice for writing names of methods, variables, classes, packages, and constants. The
camelCase naming convention makes compound names more readable. For example, myOneMethod is easier to
read than myonemethod.

Pascal case: Pascal case is similar to camel case, but the first word is also capitalized. Example: FirstName,
LastName, PrintFullName().

Snake case: Snake case (stylized as snake_case) refers to the style of writing in which each space is replaced by an
underscore (_) character, and the first letter of each word written in lowercase. It is a commonly used naming
convention in computing, for example for variable and subroutine names, and for filenames. Snake case uses all
lowercase letters and underscores to separate words. Example: first_name, last_name, print_full_name(). Python
uses snake_case.

Kebab case: Kebab case is similar to snake case but with hyphens instead of underscores. Example: first-name,
last-name, print-full-name().

A Software Professional to remember the following:


Jobs may involve working on legacy code – making it boring/mundane. Lot of maintenance work is required for
software.
Or,
the job may be completely different such as a startup where the technology stack is completely different – such as
use of Java, Linux, Distributed Systems, write code that simulated statistical equations in programming language
called R, Build complex Graphs using JavaScript and a frame called D3.
Importance of starting out with a good programming language – say JavaScript. Do your research and go for it as
per the times. Learning too many programming languages is not helpful, instead if you master a programming
language and not just the syntax but what surrounds the programming language - networks, cyber security,
deployment, debugging, testing

Importance of writing clean and readable code.

Mastering the key concepts is very important as technology evolves rapidly.

People skills and building trust within the team is very important.

Software is built to solve other people’s problems not your problems.

Namespaces and Scope in Python


A namespace is basically a system to make sure that all the names in a program are unique and can be used
without any conflict. You might already know that everything in Python—like strings, lists, functions, etc. —is an
object. Another interesting fact is that Python implements namespaces as dictionaries. A namespace is a system
that has a unique name for each and every object in Python. An object might be a variable or a method.
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables,
etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can
occur especially when your code base includes multiple libraries.
A namespace is a collection of currently defined symbolic names along with information about the object that each
name references. You can think of a namespace as a dictionary in which the keys are the object names and the
values are the objects themselves.
In simple words, A namespace is a collection of names and the details of the objects referenced by the names. We
can consider a namespace as a python dictionary which maps object names to objects. The keys of the dictionary
correspond to the names and the values correspond to the objects in python.

When Python interpreter runs solely without any user-defined modules, methods,
classes, etc. Some functions like print(), id() are always present, these are built-in
namespaces. When a user creates a module, a global namespace gets created, later the
creation of local functions creates the local namespace. The built-in
namespace encompasses the global namespace and the global namespace encompasses
the local namespace.
Global namespaces are defined at the program or module level. It contains the names
of objects defined in a module or the main program. A global namespace is created
when the program starts and exists until the program is terminated by the python interpreter.
A variable created inside a function belongs to the local scope of that function, and can only be used inside that
function.

As explained in the example above, the variable x is not available outside the function, but it is available for any
function inside the function:

A variable created in the main body of the Python code is a global variable and belongs to the global scope.
Global variables are available from within any scope, global and local.

If you operate with the same variable name inside and outside of a function, Python will treat them as two separate
variables, one available in the global scope (outside the function) and one available in the local scope (inside the
function):
If you need to create a global variable, but are stuck in the local scope, you can use the global keyword.
The global keyword makes the variable global.

Program for ‘Tossing a coin’

Program to play Snakes and Ladders – value of die thrown

Caesar Cipher in Cryptography


‘while’loop

Factorial of a natural number using ‘while’loop


Factorial of a natural number using ‘while’loop

Factorial of a natural number using ‘if’statement and ‘while’ loop

Python program to check if a number is positive, negative or zero.

Python ‘for’loop.
‘for’ loop and ‘range’ function

Multiplication table using ‘for’ loop and ‘range’ function.

‘for’ loop in Python


Python ‘break’ statement

Python ‘continue’ statement


In python, ‘pass’is a null statement that does nothing. The ‘pass’statement is used to create loops, if…else
statement, functions and classes within an empty body.
In Python programming, the pass statement is a null statement. The difference between a comment and
a pass statement in Python is that while the interpreter ignores a comment entirely, pass is not ignored.
However, nothing happens when the pass is executed. It results in no operation (NOP).
‘User Defined Functions’ in Python

Note: In python, the function definition should always be present before the function call. Otherwise, we will get an
error.
Python function to add two numbers

Python function to multiply two numbers

Finding number of elements and the sum of elements of a List in Python

Passing arguments to a function

Given marks of various subjects, to find the average score and also the Grade
Printing odd numbers in a range function using ‘step’

You might also like