We've moved! — MindVault360 is now SrcForge. Better design, more content & premium notes.

Visit SrcForge →

MindVault360 has moved!

We've upgraded to SrcForge — a faster, more professional platform with better content, premium notes, and a modern design.

Visit us at SrcForge

Friday, March 29, 2024

Introduction to Python


Introduction:

Python is a versatile and advanced programming language that is noted for its ease of use and readability. Python, created by Guido van Rossum and launched in 1991, has since become one of the most popular programming languages globally, used in a variety of domains.

 Features:

1. Easy to Learn and Read:

Python's syntax is basic and understandable, making it suitable for novices. Its readability promotes clean, maintainable programming.

2. Wide Range of Libraries and Frameworks: 

Python has a rich ecosystem of libraries and frameworks for a variety of activities, including web development, data analysis, machine learning, scientific computing, and more. These libraries help developers save time and effort by providing pre-built solutions to common problems.

3. Cross-Platform Compatibility: 

Python is cross-platform, which means it can run on a variety of operating systems including Windows, macOS, and Linux without any modifications. This enables developers to write code once and deliver it to various platforms.

4. Interpreted Language

Python is an interpreted language, which means that an interpreter reads each line of code and runs it. This enables quick development and testing without the requirement for compilation.

5.Dynamic Typing and High-Level Language:

Python is dynamically typed, thus you don't have to declare variable types directly. It also abstracts away low-level details, allowing developers to concentrate on problem solving rather than memory management or other system-level tasks.

6. Object-Oriented Programming Support:

Python supports the object-oriented programming (OOP) paradigm, which enables developers to write reusable and modular code using classes and objects.

7.Integration Capabilities:

Python is easily compatible with other programming languages such as C/C++, Java, and.NET. This enables developers to use existing codebases and libraries developed in other languages.

8.Versatility:

Python is a general-purpose programming language, which means it may be used in a variety of applications. Whether you're creating a small script, a web application, or a large machine learning model, Python has the tools and libraries you need.

 

Scope of Python:


1. Web Development: 

Python provides strong frameworks for developing web applications, like Django and Flask. These frameworks offer capabilities for rapid development, scalability, and security, making Python a popular choice for web developers.

2. Data Science and Analytics: 

Python is widely used in data science and analytics thanks to libraries such as Pandas, NumPy, and SciPy, which allow for data manipulation, analysis, and visualization. Additionally, technologies like Jupyter Notebooks make it simple to examine and display data in a collaborative setting.

3. Machine Learning and Artificial Intelligence: 

Python has emerged as the standard language of choice for machine learning and artificial intelligence research. TensorFlow, PyTorch, and scikit-learn are strong libraries for building and training machine learning models, neural networks, and deep learning algorithms.

4. Scientific Computing: 

Python is commonly used in scientific computing to perform tasks such as simulation, modeling, and numerical analysis. SciPy and SymPy are libraries that provide advanced mathematical functions and tools for scientific study and engineering.

5. Automation and Scripting: 

Python's simplicity and ease of use make it suitable for automated and scripted activities. It is often used for creating scripts that automate repetitive processes, system administration, and workflow management.

6. Game Development: 

Python is increasingly being used in game creation due to its simplicity and the availability of libraries such as Pygame and Panda3D, which help with game development and prototyping.

7. DevOps and System Administration: 

Python is widely used among DevOps engineers and system administrators for activities such as configuration management, infrastructure automation, and scripting. Tools such as Ansible and SaltStack use Python to automate and orchestrate IT infrastructure.

8. Internet of Things (IoT): 

Python's lightweight nature and versatility make it ideal for IoT development. Libraries such as MicroPython and CircuitPython allow you to program microcontrollers and IoT devices.

9. Desktop GUI Applications: 

Python can be used to create desktop GUI applications with frameworks such as Tkinter, PyQt, and wxPython. These libraries enable developers to construct cross-platform desktop applications with advanced graphical interfaces.

10. Education and Research:

Python's readability and ease of use make it a popular choice in teaching and research settings. Many universities and research institutions use Python to teach programming and conduct research in a variety of areas.


← Back Next →

Labels:

Tokens & Manipulators in CPP

 


 Tokens are the smallest individual units of the program

Types:

1. Keywords.

2. Identifiers

3. String

4. Constants

5. Operators

Keywords


  • Keywords have set meanings, which cannot be modified.
  • There are 32 keywords in 'C++'.
  • Keywords are typed in lowercase letters.
  • These keywords provide developers with the essential building blocks of C++ syntax and semantics, allowing them to effectively specify a wide range of programming constructions and operations.
  • To build correct and productive C++ programs, one must first understand their meanings and applications.


 Example

  • int

  • double 

  • float

  • class

  • for


Identifiers

  • In programming languages such as Java, identifiers are the names assigned by the programmer to entities such as variables, functions, arrays, classes, and objects. These names are used to uniquely identify these entities inside their respective scopes.


Variables: Identifiers for variables serve as labels for data values. A variable identifier can represent a raw data type, such as an integer or character, as well as a class instance.

Functions: Function identifiers name a block of code designed to perform a specific task. When the function is called using its identifier, the block of code executes.

Arrays: An array identifier refers to a collection of elements that are of the same type. The identifier allows access to the array and its elements through indexing.

 Following rules must be followed for identifiers:
  • The first character must always be an alphabet or an underscore.

  • It should be formed using only letters, numbers, or underscore.

  • A keyword cannot be used as an identifier.

  • It should not contain any whitespace character.

  • The name must be meaningful.


 Example of valid identifiers

           Sum_1,  result


Example of invalid identifiers

  • 1Sum -> starts with number

  • Sum*1 -> * (asterisk) not allowed



Constants

  • Constants are the fixed values that never change during the execution of a program.

 Integer Constants

  • An integer constant is nothing but a value consisting of digits or numbers

  Example : 111, 1234

 Floating point Constants

  • constants that contain a decimal point or a fraction value. 

 Example: 223.14, 400.054

 Character Constants

  • A character constant contains only a single character enclosed within a single quote (‘ '). 

 Example: ‘A’ , ‘m’, ‘9’

 String Constants

  • A string constant contains a sequence of characters enclosed within 

double quotes (“ ").

  Example: “Welcome”, “Hello”

Strings

  • Strings are nothing but an array of characters ended with a null character (‘\0’)

  • Strings are always enclosed in double quotes.

 Example: “Welcome”


Operators

  • Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations

 Example: +, -, /, *, ++, --


1. Arithmetic Operators

Arithmetic operators are used for performing basic mathematical operations on operands.

Operator

         Name

         Description

Example     

+

         Addition

         Adds together two values

         x + y

-

         Subtraction

         Subtracts one value from another

         x - y 

*

         Multiplication

         Multiplies two values

         x * y 

/

         Division

         Divides one value by another

         x / y 

%

         Modulus

         Returns the division remainder

         x % y

++

         Increment

Increases the value of a variable by 1

         ++x 

--

         Decrement

         Decreases the value of a variable by 1

         --x   

Example 01:

// Working of arithmetic operators
#include <iostream>
using namespace std;

int main() {
    int a = 9,b = 4;

    cout<<"a+b = "<<a+b<<endl;

    cout<<"a-b = "<<a-b<<endl;

    cout<<"a*b ="<<a*b<<endl;

    cout<<"a/b = "<<a/b<<endl;

    cout<<"Remainder when a divided by b =  "<<a%b;

    return 0;
}

 

Example 02:

// Working of increment and decrement operators
#include <iostream>
using namespace std;

int main()
{
    int a = 10, b = 100;
    float c = 10.5, d = 100.5;

    cout<<"++a =  "<< ++a;
    cout<<"--b =  "<< --b;
    cout<<"++c =  "<< ++c;
    cout<<"--d =  "<< --d;

    return 0;
}


2. Assignment Operators


        Assignment operators are used to assign value to a variable. 

 

Operator

Example

Same As

=

x = 5

x = 5

+=

x += 3

x = x + 3

-=

x -= 3

x = x - 3

*=

x *= 3

x = x * 3

/=

x /= 3

x = x / 3

%=

x %= 3

x = x % 3

&=

x &= 3

x = x & 3

|=

x |= 3

x = x | 3

^=

x ^= 3

x = x ^ 3

>>=

x >>= 3

x = x >> 3

<<=

x <<= 3

x = x << 3



Example 03:


// Working of assignment operators
#include <iostream>
using namespace std;

int main()
{
    int a = 5, c=20;

    c += a;    
    cout<<"c = "<< c;
    c -= a;  
    cout<<"\nc = "<< c;
    c *= a;    
    cout<<"\nc = "<< c;
    c /= a;    
    cout<<"\nc = "<< c;
    c %= a;    
    cout<<"\nc = "<< c;

    return 0;
}


3. Logical Operators


        Logical operators are used for evaluating a combination of conditions/constraints to get a resultant value.

         The result of the evaluation of a Boolean expression is Boolean which is either true or false. 

 

Operator

Name

Description

Example

&&

Logical and

Returns true if both statements are true

x < 5 &&  x < 10

||

Logical or

Returns true if one of the statements is true

x < 5 || x < 4

!

Logical not

Reverse the result, returns false if the result is true

!(x < 5 && x < 10)


Example 04:



#include <iostream>
using namespace std;

int main() {
    bool result;

    result = (3 != 5) && (3 < 5);     // true
    cout << "(3 != 5) && (3 < 5) is " << result << endl;

    result = (3 == 5) && (3 < 5);    // false
    cout << "(3 == 5) && (3 < 5) is " << result << endl;

    result = (3 == 5) && (3 > 5);    // false
    cout << "(3 == 5) && (3 > 5) is " << result << endl;

    result = (3 != 5) || (3 < 5);    // true
    cout << "(3 != 5) || (3 < 5) is " << result << endl;

    result = (3 != 5) || (3 > 5);    // true
    cout << "(3 != 5) || (3 > 5) is " << result << endl;

    result = (3 == 5) || (3 > 5);    // false
    cout << "(3 == 5) || (3 > 5) is " << result << endl;

    result = !(5 == 2);    // true
    cout << "!(5 == 2) is " << result << endl;

    result = !(5 == 5);    // false
    cout << "!(5 == 5) is " << result << endl;

    return 0;
}



4. Comparison Operators


        Relational or comparison operators are used to compare two operands.

        The result of the evaluation is either true or false.

 

Operator

Name

Example

==

Equal to

x == y

!=

Not equal

x != y

> 

Greater than

x > y

< 

Less than

x < y

>=

Greater than or equal to

x >= y

<=

Less than or equal to

x <= y


Example 05:


#include <iostream>
using namespace std;

int main() {
    int a, b;
    a = 3;
    b = 5;
    bool result;

    result = (a == b);   // false
    cout << "3 == 5 is " << result << endl;

    result = (a != b);  // true
    cout << "3 != 5 is " << result << endl;

    result = a > b;   // false
    cout << "3 > 5 is " << result << endl;

    result = a < b;   // true
    cout << "3 < 5 is " << result << endl;

    result = a >= b;  // false
    cout << "3 >= 5 is " << result << endl;

    result = a <= b;  // true
    cout << "3 <= 5 is " << result << endl;

    return 0;
}



(Other Operators)


scope resolution operator is ::


Use of scope resolution operator: To access a global variable when there is a local variable with same name


Example 06:

int x=20;  // Global x 

   

void main() 

  int x = 10; // Local x 

  cout << "Value of global x is " << ::x; 

  cout << "\nValue of local x is " << x;   

 } 

Output

Value of global x is 20 

Value of local x is 10








← Back Next →

Labels: