Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Mohd Mohtashim
Page 6 of 19
Python Environment Variables
Environment variables in Python control how the Python interpreter behaves and where it searches for modules and configuration files. Understanding these variables helps you customize Python's runtime environment and resolve import issues. Key Python Environment Variables Variable Description Example Usage PYTHONPATH Specifies additional directories where Python searches for modules. Similar to the system PATH variable but for Python imports. export PYTHONPATH=/path/to/modules PYTHONSTARTUP Path to a Python file that runs automatically when the interactive interpreter starts. Useful for loading common imports or utilities. export PYTHONSTARTUP=~/.pythonrc.py PYTHONCASEOK On Windows, ...
Read MoreInstalling Python on Linux
Python is a versatile programming language that can be installed on Linux systems through multiple methods. Whether you choose to compile from source or use your distribution's package manager, installing Python on Linux gives you access to the latest features and libraries. Method 1: Installing from Source Code Installing Python from source code provides maximum flexibility and control over features ? Prerequisites Ensure you have essential build tools installed ? sudo apt-get update sudo apt-get install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget Download and Install Follow these steps ...
Read MoreWhy You Should Learn Python Programming?
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where other languages use punctuation, and it has fewer syntactical constructions than other languages. Python is a MUST for students and working professionals to become a great Software Engineer, especially when working in Web Development, Data Science, or AI domains. Here are the key advantages of learning Python ? Core Features of Python Python is Interpreted Python is processed at runtime by the interpreter. You do not need to compile your program before executing ...
Read MoreHow to create an image to zoom with CSS and JavaScript?
Image zoom effects allow users to see enlarged details of an image by hovering over different areas. This is commonly used in e-commerce websites and galleries to provide better product viewing experience. Syntax The image zoom effect combines CSS positioning and JavaScript event handling − .img-zoom-container { position: relative; } .img-zoom-lens { position: absolute; border: 1px solid #d4d4d4; } .img-zoom-result { background-image: url(image.jpg); background-size: calculated-size; background-position: calculated-position; } ...
Read MoreThe Match Operator in Perl
The match operator m// in Perl, is used to match a string or statement to a regular expression. For example, to match the character sequence "foo" against the scalar $bar, you might use a statement like this −Example#!/usr/bin/perl $bar = "This is foo and again foo"; if ($bar =~ /foo/) { print "First time is matching"; } else { print "First time is not matching"; } $bar = "foo"; if ($bar =~ /foo/) { print "Second time is matching"; } else { print "Second time is not matching"; }When above program is executed, it ...
Read MoreMatching Only Once in Perl
There is a simpler version of the match operator in Perl - the ?PATTERN? operator. This is basically identical to the m// operator except that it only matches once within the string you are searching between each call to reset.For example, you can use this to get the first and last elements within a list −Example#!/usr/bin/perl @list = qw/food foosball subeo footnote terfoot canic footbrdige/; foreach (@list) { $first = $1 if /(foo.*?)/; $last = $1 if /(foo.*)/; } print "First: $first, Last: $last";When the above program is executed, it produces the following result −First: foo, Last: footbrdige
Read MoreThe Substitution Operator in Perl
The substitution operator s/// in Perl is really just an extension of the match operator that allows you to replace the text matched with some new text. The basic form of the operator is −s/PATTERN/REPLACEMENT/;The PATTERN is the regular expression for the text that we are looking for. The REPLACEMENT is a specification for the text or regular expression that we want to use to replace the found text with. For example, we can replace all occurrences of dog with cat using the following regular expression −Example#/user/bin/perl $string = "The cat sat on the mat"; $string =~ s/cat/dog/; print "$string";When the above program is ...
Read MoreGrouping Matching in Perl
From a regular-expression point of view in Perl, there is no difference between the following two expressions except that the former is slightly clearer.$string =~ /(\S+)\s+(\S+)/; and $string =~ /\S+\s+\S+/;However, the benefit of grouping is that it allows us to extract a sequence from a regular expression. Groupings are returned as a list in the order in which they appear in the original. For example, in the following fragment we have pulled out the hours, minutes, and seconds from a string.my ($hours, $minutes, $seconds) = ($time =~ m/(\d+):(\d+):(\d+)/);As well as this direct method, matched groups are also available within the ...
Read MoreThe G Assertion in Perl
The \G assertion in Perl allows you to continue searching from the point where the last match occurred. For example, in the following code, we have used \G so that we can search to the correct position and then extract some information, without having to create a more complex, single regular expression −Example#!/usr/bin/perl $string = "The time is: 12:31:02 on 4/12/00"; $string =~ /:\s+/g; ($time) = ($string =~ /\G(\d+:\d+:\d+)/); $string =~ /.+\s+/g; ($date) = ($string =~ m{\G(\d+/\d+/\d+)}); print "Time: $time, Date: $date";When the above program is executed, it produces the following result −Time: 12:31:02, Date: 4/12/00The \G assertion is actually ...
Read MoreWhat are Packages in Perl?
The package statement in Perl switches the current naming context to a specified namespace (symbol table). Thus −A package is a collection of code which lives in its own namespace.A namespace is a named collection of unique variable names (also called a symbol table).Namespaces prevent variable name collisions between packages.Packages enable the construction of modules which, when used, won't clobber variables and functions outside of the modules's own namespace.The package stays in effect until either another package statement is invoked, or until the end of the current block or file.You can explicitly refer to variables within a package using the :: package ...
Read More