- The mkdir command is used to create new directories
A directory, referred to as a folder in some operating systems, appears to the user as a container for other directories and files. Unix-like operating systems treating directories as a special type of file that contains a list of filenames and their corresponding inode numbers. Each inode number refers to an inode, which is located in inode tables (which are kept at strategic locations around the filesystem) and which contains all information about a file (i.e. file, permissions and date of creation) except its name and the actual data that the file contains. Source
An inode is a data structure on a filefyftem on Linux and other Unix-like operating systems that stores all information about a file except its name and its actual data.
A data structure is a way of storing data so that it can be used efficiently.
A filesystem is the hierarchy of directories that is used to orginise file on a computer. On Unix-like operating systems, the directories start with the root directory, which contains a series of subdirectories, each of which, in turn, may contain further subdirectories, etc.
A file is a named collection of related information that appears to the user as a single, contiguos block of data and that is retained in storage. It does not automaticcaly contain information about itself, unless some human purposly adds in such data. Such information about a file, in contrast to the data contained in a file, is its metadata. Source
-
The print statement evaluates each expression in turn and writes the resulting object to standard output. If an object is not a string, it is first converted to a string using the rules for string conversions. The (resulting or original) string is then written. A space is written before each object is written, unless the output system belives it is positioned at the beginning of a line. This is the case
- when no characters have yet been written to standard output,
- when the last character written to standard output is a whitespace character except "' '", or
- when the last write operation on standard output was not a "print" statement.
-
Standard output is defined as the file object named stdout in the build-in module sys. If no such object exists, or if it does not have a "write()" method, a "RuntimeError" exception is raised. Source
-
Comments in Python start with the *hash character, #, and extend to the end of the physical line. A comment may appear at the start of a line or following whitespace or code, but not within a string literal. A hash character within a string literal is just a hash character. Source
Python language supports the following types of operators:
- Arithmetic Operators,
- Comparison (Relational) Operators,
- Assignment Operators,
- Logical Operators,
- Bitwise Operators,
- Membership Operators,
- Identity Operators.
Assume variable a holds 10 and variable b holds 20, then
- + Addition - Adds values on either side of the operator: a + b = 30
- - Subtraction - Subtracts right hand operand from left hand operand: a - b = -10
- *** Multiplication** - Multiplies values on either side of the operator: a * b = 200
- / Division - Divides left hand operand by right hand operand: b / a = 2
- % Modulus - Divides left hand operand by right hand operand and returns remainder: b % a = 0
- ** Exponent - Performs exponential (power) calculation on operators: a ** b = 10 to the power of 20
- // Floor division - The division of operands where the result is the quotient in which the digits after the decimal poin are removed. But if one of the operands is negative, the result is floored, i.e. rounded away from zero (towards negative infinity): 9 // 2 = 4 and 9.0 // 2.0 = 4.0, -11 // 3 = -4, -11.0 // 3 = -4.0 Source
These opeartors compare the values on either sides of them and decide the relation among them.
Assume variable a holds 10 and variable b holds 20, then
- == - If the values of two operands are equal, then condition becoms true: (a == b) is not true.
- != - If values of two operands are not equal, then condition becomes true: (a != b) is true.
- <> - If values of two operands are not equal, then condition becomes true: (a <> b) is true.
- > - If the value of left operand is greater than the value of right operand, then condition becomes true: (a > b) is not true.
- < - If the value of the left operand is less than the value of right operand, then conditions becomes true: (a < b) is true.
- >= - If the value of left operand is greate than or equal t the value of right operand, then condition becomes trye: (a >= b) is not true.
- <= - If the value of left operand is less than or equal to the value of the right operand, then condition becomes true: (a <= b) is true. Source
Assume variable a holds 10 and variable b holds 20, then
- = - Assigns values from the right side operand to left side operand: c = a, assigns value of a to c
- += Add AND - It adds right operand to the left operand and assign the result to left operand: c += a is eqivalent to c = c + a.
- -= Subtruct AND - It subtracts right operand from the left operand and assign the result to left operand: c -= a is equivalent to c = c - a.
- *= Multiply AND - It multiplies right operand with the left operand and assign the result to the left operand: c *= a is equivalent to c = c * a.
- /= Divide AND - It divides left operand with the right operand and assign result to left operand: c /= a is equivalent to c = c / a.
- %= Modulus AND - It takes modulus using two operands and assign the result to left operand: c %= a is equivalent to c = c % a.
- **= Exponent AND - Performs exponential (power) calculation on operands and assign value to left operand: c **= a is equivalent to c = c ** a.
- //= Floor Division - It performs floor division on operator and assign value to the left operand: c //= a is equivalent to c = c // a. Source
Bitwise operator works on bits and performs bit by bit operation. Assume if a = 60 and b = 13. Now in binary format they will be as follows: a = 0011 1100 b = 0000 1101 --------------- a & b = 0000 1100 a | b = 0011 1101 a ^ b = 0011 0001 ~a = 1100 0011 a << 2 = 240 (1111 0000) a >> 2 = 15 (0000 1111)
There are following Bitwise operators supported by Python language:
- & Binary AND - Operator copies a bit to the result if it exists in both operands.
- | Binary OR - It copies a bit if it exists in either operand.
- ^ Binary XOR - It copies the bit if it is set in one operand but not both.
- **~ Binary Ones Complement** - It is unary and has the effect of 'flipping' bits.
- << Binary Left Shift - The left operands values is moved left by the number of bits specified by the right operand.
- >> Binary Right Shift - The left operands values is moved right by the number of bits specified by the right operand. Source
Assume variable a holds 10 and variable b holds 20, then
- and Logical AND - If both the operands are true then condition becomes true: (a and b) is true.
- or Logical OR - If any of the two operands are non-zero then condition becomes true: (a or b) is true.
- not Logical NOT - Used to reverse the logical state of its operand: not(a or b) is false.
Python membership operators test for membership in a sequence, such as strings, lists, or tuples.
- in - Evaluates to true if it finds a variable in the specified sequence and false otherwise.
- not in - Evaluates to true if it does not find a variable in the specified sequence and false otherwise. Source
Identity operators compare the memory locations of two objects.
- is - Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. x is y, here is results in 1 if id(x) equals id(y).
- is not - Evaluates to false if the variables on either side of the operator point to the same object and true otherwise. x is not y , here is not results in 1 if id(x) is not equal id(y).
- ** Exponentiation.
- ~, +, - Complement, unary plus and minus.
- *, /, %, // Multiply, divide, modulo and floor division.
- +, - Addition and subtruction.
- <<, >> Right and left bitwise shift.
- & Bitwise 'AND'.
- ^, | Bitwise exclusive 'OR' and regular 'OR'.
- <=, <, >, >= Comparison operators.
- <>, ==, != Equality operators.
- =, %=, /=, //=, -=, +=, *=, **= Assigment operators.
- is, is not Identity operators.
- in, not in Membership operators.
- not, or, and Logical operators. Source
This is the list of all the escape sequences Python supports.
- \\ Backslash (\)
- \' Single-quote(')
- \" Double-quote(\")
- \a ASCII bel (BEL)
- \b ASCII backspace (BS)
- \f ASCII formfeed (FF)
- \n ASCII linefeed (LF)
- \N{name} Character named name in the Unicode database (Unicode only)
- \r ASCII carriage return (CR)
- \t ASCII horizontal tab (TAB)
- \uxxxx Character with 16-bit hex value xxxx (Unicode only)
- \Uxxxxxxxx Character with 32-bit hex value
- \v ASCII vertical tab (VT)
- \ooo Character with octal value oo
- \xhh Character with hex value hh