Posts

Showing posts from 2024

Loop: for & range

Image
for loop : it is used to iterate over a sequence (like a list, tuple, string, or range). The loop executes a block of code once for each item in the sequence. Normally range function is used with for. The range() Function The  range() function is used to generate a sequence of numbers. It's commonly used in loops, especially for loops, to iterate over a sequence of numbers. The function supports three main parameters: start , stop , and step . Here's a breakdown: SYNTAX: range (start, stop, step) Example: in code bellow we print X for i starting from Start value 0 and ending to 9 (Stop value -1) range with steps Example: in code bellow we print X for i starting from Start value 0 and ending to 9 (Stop value -1) but in step of 2.

Data Types

Image
 Data Types in Python. Python data types: None Type:    None String data types: str. Numeric data types: int, float, complex. Binary types: bytes, bytearray, memory view Boolean type: bool Sequence types: list, tuple, range. Mapping data type: dict. Set data types: set, frozenset. We can use type() function to verify data type used. Data used in python can be categorized as. Public, private, or protected data Primitive or non-primitive Mutable or immutable data types: Sequence (sting, list, tuple), Boolean (True, False), dictionary, number (int, float, complex) Data Type Example Sequential Numeric Y=Primitive Y=Mutable N=Non-Primitive N=immutable String "Hello" Y   Y N List [“apple”,1, “red”] Y   N Y Tuple (1, “Goa”,5,6) Y   N N Integer 123 ...

Output (print) Input function.

Image
 To display or print message on standard i/o we use print function. SYNTEX:  To print specific character. print("Character") To print variable assuming variable name / id is name. print(name) To get input data. input() variable-name=input("Message to display") Data collected will be saved as value for variable-name to print collected data we can use print(variable-name) Note: print statement with " " quote print string. If there is no quote it is consider as variable. So print("name") will print character name, while print(name) will print value of variable name. 

Introduction to Python.

Image
Installation of Python: For windows version available.   X 64 version for 64 bit OS X 86 version for 32 bit OS Document comes with CHM (compiled HTML) ----------------------------------------------------------------------------------------------------------- Setup System Variable.  Once Python is installed setup system variable. It helps to Run python from any prompt, no need to run python code from installed directory.   Method 1 %path%;C:\Python-path   (Python-path = location where python is installed) SYStem Device Manager Control PaneL applet:   Or   Method 2:  (System Device Manager Control Panel applet) Run and type sysdm.cpl Click on "Advanced" tab of system properties  Environment Variables Set path variable: c:\Program Files\Python310 --------------------------------------------------------------------------------------------------------------- To Verify Version of Python:    python -V ---------------...

Computer Programming Brief History.

Brief history: Python was developed by Guido van Rossum in early 90s at the National Research Institute for Mathematics and Computer Science in the Netherlands.  Python is derived from many other languages C, Unix shell and other scripting languages. Python is copyrighted. is available under the GNU General Public License (GPL).  Computer Programming: Programmer High Level Language (Python) Low Level Language (Assembly) Machine Level Language ( Binary) Computer Hardware Style of writing program. Procedural programming : A list of steps for a computer to follow. E.g. Fortran, Pascal Imperative programming A procedural style of programming that requires programmers to define step-by-step instructions for the computer. E.g. C++, Java.  Object-oriented programming (OOP) A programming paradigm that structures programs by bundling properties and behaviors together as an object.  Scripting languages A general-purpose procedural language that directs interaction with a compu...