Saturday, 24 June 2017

What is a Cookie in PHP | Softcrayons IT Training Tutorial



A cookie is a small file that the server embeds on the user’s
computer. Each time the same computer requests a page with a browser, it
will send the cookie too. With PHP, you can both create and retrieve
cookie values.


A cookie is created with the setcookie() function.


Now we learn how to create and retrieve Cookie





This example creates a cookie named “user” with the value “John Doe”.
The cookie will expire after 30 days (86400 * 30). The “/” means that
the cookie is available in entire website (otherwise, select the
directory you prefer).


We then retrieve the value of the cookie “user” (using the global variable $_COOKIE). We also use the isset() function to find out if the cookie is set:


<?php

$cookie_name = “user”;

$cookie_value = “John Doe”;

setcookie($cookie_name, $cookie_value, time() + (86400 * 30), “/”); // 86400 = 1 day

?>

<html>

<body>


<?php

if(!isset($_COOKIE[$cookie_name])) {

echo “Cookie named ‘” . $cookie_name . “‘ is not set!”;

} else {

echo “Cookie ‘” . $cookie_name . “‘ is set!<br>”;

echo “Value is: ” . $_COOKIE[$cookie_name];

}

?>


</body>

</html>


You will get the out out of this


Cookie named ‘user’ is not set!


Note: You might have to reload the page to see the value of the cookie.

What is a Cookie in PHP | Softcrayons IT Training Tutorial

Saturday, 17 June 2017

How to use Syntax Differences between Python 2 and Python 3 | Softcrayons IT Training Tutorial

For beginners, there are few points to remember if you have thought of learning Python. We will Discuss 2 of them here:


  1. Printing values on screen
  2. User input
There are many more small differences that I won’t get into for now.





  1. Printing values
The first most basic difference you will notice b/w python 2 and python 3 versions is printing values on the screen.





Python 2 Python 3
print“Hello” print(“Hello”)



In python 2, to print a value you just need to apply quotes after
print syntax because print behaves as an operator, which means it
operates on whatever comes after it. In python 3, print is a function
that takes arguments, So parenthesis are must.


So remember whenever you see error like this


>>>print“Lucious”File”<stdin>”,line1print“Lucious”^SyntaxError:Missingparenthesesincallto’print’  It means you were trying use python 2 syntax in python 3. 2.    User Input Next
difference you should know is about user input used to take values from
user. In python 2 the raw_input()function was used but in python 3 it
is removed and is replaced by input()


It means for both strings and integers you will use this functions only if working in python 3.



How to use Syntax Differences between Python 2 and Python 3 | Softcrayons IT Training Tutorial

Thursday, 15 June 2017

How to use INHERITENCE in PYTHON | Softcrayons IT Training Tutorial

  • OOP(object oriented programming) :
  • Programming that is based around classes and instances of those classes.
  • OOPs programming revolves around how these classes interact and directly affect one another.
  • One of the most imp aspect of oops is INHERITENCE.



  • INHERITENCE :
  • It is when one class gains all the attributes of another class.
  • In inheritance you ‘ve a parent class and then children classes.
    That inherit features from the parent class. One of the great thing of
    inheritance is that you can have as many subclasses as you want. You can
    ‘ve as many classes u want inherit from the same class.



Example- 1





As u can see we have 2 classes, date and time. Look closely at the
class we see object in the parenthesis and date in the argument of time.
What this means is that time inherits from date and date inherits from
class called object.


Object is the built in class provided by python. Now take a look
below, we created new date object(dt) and then we create a new time
object(tm) .





Now look we are also able to call get_date on the time object, it is
specifically because we place the date class name in the argument list
of the time class definition. So they were able to call a date method
ona time object. We can illustrate this by trying to run program without
having date as parameter in time














class.


Now time doesn’t inherit from date. We get a error.





Inheritance is simply another level of attribute lookup. Remember
when we ask a instance to give us the value of an attribute, we call a
method using object .attribute syntax, we initiating a lookup that
precedes from place to place in a particular order. As we know when we
ask a object for an attribute, it uses a lookup hierarchy. When we say
object .attribute, in this case let us say





that is attribute look up.





NOW there are 3 places where python looks for an attribute in the instance.



How to use INHERITENCE in PYTHON | Softcrayons IT Training Tutorial

How to use Python string swapcase() Method | Softcrayons IT Training Tutorial

swapcase()method
returns a string in which all the case are swapped based on their
characters. It goes not take any arguments remember that.


Syntax


str.swapcase()





Examples


str= “hello to this new world”


printstr.swapcase()





str=”HELLO TO THIS NEW WORLD”


printstr.swapcase()





str=”Hello to This new World”


printstr.swapcase()


When we run our program we will see following output on our console


HELLO TO THIS NEW WORLD


hello to this new world


hEELO TO tHIS NEW wORLD










Updated: June 9, 2017 at 12:40 pm


How to use Python string swapcase() Method | Softcrayons IT Training Tutorial

How to use Python string swapcase() Method | Softcrayons IT Training Tutorial

How to use Python string swapcase() Method | Softcrayons IT Training Tutorial

Monday, 12 June 2017

How to use Split() Method in python | Softcrayons IT Training Tutorial



Today we will learn about split() method in python which is very useful in our programming.


Syntax


str.split([x,num])


Parameters


  • X – the character after which you want to break the
    value. It can be any character you want and default it takes space as
    it argument.
  • num- this is number of lines to be made
Example


a=”the way you see people is the way they became”


printa.split()


printa.split(” “,1)








The above program will show following output


[‘the’, ‘way’, ‘you’, ‘see’, ‘people’, ‘is’, ‘the’, ‘way’, ‘they’, ‘became’]


[‘the’, ‘way you see people is the way they became’]





This would be more understood by a practical example. Suppose
you need to make a program that should take comma as a separator and
find the length of words. Means after comma it should consider every
value separated.



So in this program we will take user input and it should separate values by a comma.


b = raw_input(“Please enter a list of strings(seperated by a comma): “)


y = []                              # empty list in which length of words will be stored


x = b.split(“,”)               #     so the user input can be separated by a comma


fori in x:                       # for taking each value individually


a = len(i)                 # it will count the length of word


y.append(a)           # it will insert data in list “y” automatically


print y





So when we will run the program it will give following result





Please enter a list of strings(seperated by a comma): aman,pap,lalu


OUTPUT


[4, 3, 4]



How to use Split() Method in python | Softcrayons IT Training Tutorial