Posts

Left Shift & Right Shift Operator in C

 X <<Y  This means left shift x by y. e.g 2<<1. So 2 in binary 0010 .After left shifting by 1 it becomes 0100 means 4 in decimal. We can calculate this easily .For left shifting result will be calculated using below formula x*2^y. X>>Y This means right shift x by y. e.g 2>>1. So 2 in binary 0010 .After right shifting by 1 it becomes 0001 means 1 in decimal. We can also calculate this easily .For right shifting result will be calculated using below formula x/2^y. However this formula will not work if the number is negative and if the shifting value is greater than the size of the integer.

পাইথন এ _ (UnderScore) এর ব্যবহার

 পাইথন এ _ এর কয়েক ধরনের ব্যবহার আছে। ১। আমরা যখন পাইথন শেল এ কোন এক্সপ্রেশন লিখি কোন ভারিয়াবলে Assign করা ছারাই,তখন সেটার মান _ এ Assign হয়ে যায়। >>> 2+3 >>>_ 5 >>>_ * 3 15 2.পাইথন এ কিছু কী-ওয়ার্ড আছে যেগুলো ভারিয়াবল হিসেবে ব্যবহার করা যাবে না।কিন্তু কী-ওয়ার্ড এর পর যদি _ ব্যবহার করি,তাহলে এরর দেখাবে না।যদিও এটা ভাল অনুশীলন না। >>>  class_ = 3 >>>  class_ * 5 15

How to create a project with virtual environment in Django(Windows 10)

Open command prompt by typing 'cmd' in windows search bar. Make a directory using 'mkdir directoryname' command. If virtualenvironment is not installed in your computer,then install it with 'pip install virtualenv' command. Create a virtual environment by 'virtualenv name' command. Now activate the virtual environment by going this 'cd->Scripts->activate' path. Now install django entering 'pip install django' command. Create a project with 'django-admin startproject projectname' command.

Swap two variables without using temporary variable

we can swap  two variables without using temporary variable in two way. 1.Using bitwise XOR operator. 2.Using addition and subtraction between two variables. Using bitwise XOR operator: a = 10    // 1010 b = 5     // 0101 a = a^b  // 1111 b = a^b  // 1010 a = a^b  //  0101 Using addition and subtraction between two variables: a = 10 b = 20 a = a+b  //30 b = a-b  //10 a = a-b  //20

List Comprehension in Python

List comprehension is a efficient way of creating a list in one line using for loop.Structure of list comprehension: list_name = [ expression | for loop | condition ] Example: If we want to find even number from a list , we can do that using list comprehension easily list_number = [1,2,3,4,5,6,7,8,9,10] list_even = [ x for x in list_number if x%2==0] print(list_even) output:[2,4,6,8,10]