Posts

Showing posts from December, 2019

PHP Filters

PHP Filters: Filters is used to validate and filter data coming from insecure sources, like user input. Runtime Configurations The behavior of these functions is affected by settings in php.ini: filter.default: Filter all $_GET, $_POST, $_COOKIE, $_REQUEST and $_SERVER data by this filter. Accepts the name of the filter you like to use by default.  Default is "unsafe_raw". filter.default_flags: Default flags to apply when the default filter is set. This is set to FILTER_FLAG_NO_ENCODE_QUOTES by default for backwards compatibility reasons. Default is "NULL".   PHP Filter Functions filter_has_var()  -  Checks whether a variable of a specified input type exist filter_id()  -  Returns the filter ID of a specified filter name filter_input()  -  Gets an external variable (e.g. from form input) and optionally filters it filter_input_array()  -  Gets external variables (e.g. from form input) and optionally filters them filter_l

Operators in Python

Arithmetic operators: Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication and division. Operator Description Syntax + Addition: adds two operands x + y - Subtraction: subtracts two operands x - y * Multiplication: multiplies two operands x * y / Division (float): divides the first operand by the second x / y // Division (floor): divides the first operand by the second x // y % Modulus: returns the remainder when first operand is divided by the second x % y Relational Operators:  Relational operators compares the values. It either returns True or False according to the condition. Operator Description Syntax >   Greater than: True if left operand is greater than the right x > y <   Less than: True if left oper

Django Commands

Here are some useful DJango commands for beginners. Using pip: To install packages >>> pip install django To uninstall packages >>> pip uninstall django Creating Virtual Environment On Unix or Mac OS >>> python3 -m venv name-env On Windows >>> python -m venv name-env Activating Virtual Environment On Windows >>> source name-env\Scripts\activate On Unix or Mac OS >>> source name-env/bin/activate Starting Django Project >>> django-admin startproject <name> Creating an app >>> python manage.py startapp <name> Different ModelFields CharField(max_length=None) DateTimeField(auto_now=False,auto_now_add=False) EmailField(max_length=None) FileField(upload_to=None,max_length=100) ImageField(upload_to=None,max_length=100) IntegerField() SlugField(max_length=50) TextField(max_length=1000) URLField(max_length=100) ForeignKey(Model

Python Interview questions and answers for experienced

1. What is a dictionary in Python? A python dictionary is something I have never seen in other languages like C++ or Java programming. It holds key-value pairs. >>> roots={25:5,16:4,9:3,4:2,1:1} >>> type(roots) - Output: <class ‘dict’> >>> roots[9] - Output: 3 A dictionary is mutable, and we can also use a comprehension to create it. >>> roots={x**2 for x in range(5,0,-1)} >>> roots {25: 5, 16: 4, 9: 3, 4: 2, 1: 1} 2. Explain the //, %, and ** operators in Python. The // operator performs floor division. It will return the integer part of the result on division. >>> 7//2 - Output: 3 Normal division would return 3.5 here. Similarly, ** performs exponentiation. a**b returns the value of a raised to the power b. >>> 2**10 - Output: 1024 Finally, % is for modulus. This gives us the value left after the highest achievable division. >>> 13%7 - Output: 6 >&g