Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

programming-fundamentals-and-python

The document provides an introduction to programming languages, focusing on Python, and outlines its components such as lexicon, syntax, semantics, standard library, interpreter, and virtual machine. It discusses the types of programming languages, coding sessions with examples of basic data types, functions, loops, and the importance of indentation in Python. Additionally, it highlights the versatility of Python for various applications including web and mobile development, game development, and data analysis.

Uploaded by

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

programming-fundamentals-and-python

The document provides an introduction to programming languages, focusing on Python, and outlines its components such as lexicon, syntax, semantics, standard library, interpreter, and virtual machine. It discusses the types of programming languages, coding sessions with examples of basic data types, functions, loops, and the importance of indentation in Python. Additionally, it highlights the versatility of Python for various applications including web and mobile development, game development, and data analysis.

Uploaded by

24f2007205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Data Science M-1: July-December 2024: NOTE 2: PROGRAMMING LANGUAGE, PYTHON

Programming Language: Introduction

(Tentative Handout)
 A programming language is a computer language, this is an artificial language designed by computer scientists
 A programming language is a set of instructions that we generally call as software, apps, applications, web-
apps, web-applications etc.
 Popular structural terms that are similar to those of a natural language, are lexicon, syntax, and semantics.
However, they are very limited, pre-defined and easy to be understood
 Programming languages resemble tiny languages, characterized by a limited dictionary, straightforward
syntax, and rigid semantic rules that ensure clarity and precision.
 Programming languages are used for various purposes, such as:
o Web development
o Mobile app development
o Game development
o Artificial intelligence
o Data analysis
o Operating systems
 Some popular programming languages include:
o Python
o Java
o JavaScript
o C++
o C#
 Two major types of programming language
o General Programming Language (GPL)
 Python, Java, C#, C++ etc.
o Domain Specific Language (DSL)
 HTML, JavaScript, CSS, XML, JSON, SQL etc.

1.1 Components of a Programming Language (with reference to python)


1. Lexicon
a. Key Words
i. Reserved words
ii. Case sensitive
iii. Limited number of words
2. Syntax
a. Syntax refers to the structure and rules of the language, determining how code should be written
to be valid.
3. Semantics
Data Science M-1: July-December 2024: NOTE 2: PROGRAMMING LANGUAGE, PYTHON
a. Semantics is the meaning behind each syntactical element, defining the behavior of valid
statements.
b. Semantics cover both the basic behavior of the language (such as primitive data types, object-
oriented principles, and control flow) and more advanced concepts like concurrency, memory
management, and exception handling.
4. Standard Library
a. The Python Standard Library is extensive and provides modules for handling various tasks, like
file I/O (os, shutil), networking (socket, http), data manipulation (collections, datetime), math
(math, random), and more.
b. Packages like json, csv, sqlite3, and re (regular expressions) make Python versatile for tasks
without needing external libraries.
5. Python Interpreter
a. Python is an interpreted language, meaning Python code is executed line-by-line by an
interpreter, rather than being compiled to machine code first.
b. The Python interpreter is responsible for parsing, compiling to bytecode, and running code on
the Python runtime. When a script is run, the interpreter translates it to bytecode (.pyc files)
6. Python Virtual Machine
a. The Python Virtual Machine is part of the interpreter that executes bytecode instructions. This makes
Python cross-platform, as long as a compatible interpreter is available.
b. The PVM manages runtime tasks like memory allocation, garbage collection, and error handling.

1.2 Language Processing Units and Mechanisms


7. Parser
a. Lexical Analyser
b. Syntax Analyser
c. Semantics Analyser

1.3 Coding Session: Python

1. Open a command prompt (cmd) / terminal


2. Make a project folder:
a. mkdir my_python_project
3. create a python file:
a. touch my_first_py_pro.py
4. open the python file
5. write a line of code or statement
a. print(‘hello world’)
6. run the python file with the command ‘python’
a. python my_first_py_pro.py
Data Science M-1: July-December 2024: NOTE 2: PROGRAMMING LANGUAGE, PYTHON
1.4 Coding Session 2: Python

7. Open a command prompt (cmd) / terminal

# Integer
my_integer = 10
print("Integer:", my_integer)

# Float
my_float = 3.14
print("Float:", my_float)

# String
my_string = "Hello, Python!"
print("String:", my_string)

# Boolean
my_boolean = True
print("Boolean:", my_boolean)
8.

1.5 Coding Session 3: Primitive Data Type, Function, Loop, Indentation


 Primitive data types are the basic, fundamental data types that are built-in to a programming
language and cannot be broken down into simpler components.
 They represent a single value or unit of data, such as numbers, characters, or boolean values, and are
typically stored in a single memory location.
 A function is a reusable block of code that performs a specific task, taking in zero or more inputs
(arguments) and returning a value or modifying external state.
 Functions encapsulate logic, making code more organized, modular, and easier to maintain.
 By calling a function, developers can execute its code multiple times without duplicating the code,
promoting efficiency and reusability.
 A loop is a programming construct that repeatedly executes a block of code for a specified number of
iterations or until a certain condition is met.
 Loops allow developers to automate repetitive tasks, process arrays or collections, and perform
iterative calculations.
 There are several types of loops, including for loops, while loops, and do-while loops, each with its
own syntax and use cases.
 Python uses indentation to define the structure of the code, specifically to denote block-level
structure.
 Indentation indicates a block of code within a control structure (e.g., if, for, while, def, class).
 All lines within a block must be indented equally.
Data Science M-1: July-December 2024: NOTE 2: PROGRAMMING LANGUAGE, PYTHON
 Indentation errors will result in a SyntaxError.

#1. Integers
age = 25
print(age) # Output: 25

#2. Floating Point Numbers


pi = 3.14159
print(pi) # Output: 3.14159

#3. Complex Numbers


complex_num = 3 + 4j
print(complex_num) # Output: (3+4j)

#4. Strings
greeting = "Hello, 78767 World!"
print(greeting) # Output: Hello, World!

#5. Boolean
is_logged_in = True #False
print(is_logged_in) # Output: True

#6. NoneType
empty_var = None
print(empty_var) # Output: None

#function
def x ():
x = 2*5
print(x)
return x

You might also like