<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Akshay Prasad on Medium]]></title>
        <description><![CDATA[Stories by Akshay Prasad on Medium]]></description>
        <link>https://medium.com/@akshayprasad199503?source=rss-1609bae59299------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yJIzhNSxRCZjAvDNqrd59w.jpeg</url>
            <title>Stories by Akshay Prasad on Medium</title>
            <link>https://medium.com/@akshayprasad199503?source=rss-1609bae59299------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:34:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshayprasad199503/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Embark on your Cybersecurity Journey: A Quick Guide to TryHackMe’s Security Engineer Learning Path]]></title>
            <link>https://akshayprasad199503.medium.com/embark-on-your-cybersecurity-journey-a-quick-guide-to-tryhackmes-security-engineer-learning-path-b6fc6faa3f16?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6fc6faa3f16</guid>
            <category><![CDATA[security-engineer]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Thu, 06 Feb 2025 07:59:56 GMT</pubDate>
            <atom:updated>2025-02-06T07:59:56.389Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I8hMIWtxyhT7HMKJtdHN1g.png" /></figure><p>The Learning path Security Engineer from TryHackMe has 5 amazing modules and are as follows:</p><ol><li><strong>Introduction to Security Engineering</strong></li><li><strong>Threat and Risks</strong></li><li><strong>Network and System Security</strong></li><li><strong>Software Security</strong></li><li><strong>Managing Incidents</strong></li><li><strong>Introduction</strong>:</li></ol><p>Introduction involves fundamentals of Security Principles, Identity and Access Management, Cryptographic algorithms, etc. It gives a solid fundamental understanding on theoretical concepts.</p><p>2. <strong>Threat and Risks</strong></p><p>This section covers plethora of frameworks, including the MITRE ATT&amp;CK, STRIDE, etc. It covers the basics of risk management and threat modeling, along with an introduction to governance and regulation. Additionally, the vulnerability management section offers insights into topics such as detecting and prioritizing vulnerabilities.</p><p>Here Vulnerability Management is one of the most interesting topics for me personally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gn2aPLEu660i5cNza3DPBA.png" /></figure><p>3. Network and System Security</p><p>This section of the module is particularly beneficial for those interested in deepening their understanding of infrastructure security. It serves as a wonderful opportunity to explore more about Linux, Windows, and networking.</p><p>You will learn concepts like Active Directory Hardening, Windows Hardening, Linux Hardening, etc and the cheat sheet is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9MCYx2DnbY4kCaDGSNXixw.png" /><figcaption>Windows Hardening Cheat Sheet</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*caM19_4aSFtusujBXExrYw.png" /><figcaption>Active Directory Hardening</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*30m4tNdZqTa0hVdKR_ypTw.png" /><figcaption>Concepts on Tiering Models</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPLOUHZ1ohryl99g8kGkOQ.png" /><figcaption>Cloud Introduction</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-FTUMd_TyS8VlhK-1IEjbg.png" /><figcaption>Log Management</figcaption></figure><p>4. <strong>Software Security</strong></p><p>This section requires a foundational knowledge and experience in web development, API security, and basic code review. The resources provided above should be helpful for beginners who may encounter challenges or need clarification on general concepts.</p><p>This section is one of the most complete sections where it has sub-section called <strong>Mother’s secret</strong> and it is quite intense and you will learn about exploiting the flaws in Application Security to reveal its secrets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*mSxU2LrdQ8tfZdsMw8xfCg.png" /><figcaption><strong>Exploit chaining</strong> or <strong>multi-stage exploitation model</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*l7On2DqjjamOwbTIfi9qkg.png" /><figcaption>SDLC life cycle example model</figcaption></figure><p>5. <strong>Managing Incidents</strong></p><p>This section talks about Incident Management and the Incident Response and how to handle during the situation with concepts such as Cyber Crisis Management, Accountability, etc.</p><blockquote>Incident Response: Is basically — “What happened?”</blockquote><blockquote>Incident Management: Is basically — “How do we respond to what happened?”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CkQeJdCCMsHOmhek4zrUBw.png" /><figcaption>Incident Management Process</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2J6lwb0izWd9q8NTyJCnw.png" /><figcaption>An example incident playbook</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FnZeQXVWtmPXgMKqZ0O8pg.png" /><figcaption>Level of Incident</figcaption></figure><h3><strong>Conclusion</strong>:</h3><p>Overall, it is a very good learning path to understand the solid fundamentals on various sections mentioned above and it can be a solid start to your Security Engineer career path.</p><p>Link to this Security Engineer Course: <a href="https://tryhackme.com/paths">TryHackMe | Paths</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*x0VAQ7S9jg69-rreHjCU0A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6fc6faa3f16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leadership styles]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://akshayprasad199503.medium.com/leadership-styles-28b4b210c0b7?source=rss-1609bae59299------2"><img src="https://cdn-images-1.medium.com/max/1056/1*Z6VrS1pppOrE0TBPRFrchQ.png" width="1056"></a></p><p class="medium-feed-snippet">What is a leadership style?</p><p class="medium-feed-link"><a href="https://akshayprasad199503.medium.com/leadership-styles-28b4b210c0b7?source=rss-1609bae59299------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://akshayprasad199503.medium.com/leadership-styles-28b4b210c0b7?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/28b4b210c0b7</guid>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[management]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Sun, 21 Apr 2024 21:10:26 GMT</pubDate>
            <atom:updated>2024-04-21T21:10:26.764Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[QBot/QakBot Malware: How does it work?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://akshayprasad199503.medium.com/qbot-qakbot-malware-how-does-it-work-2a6a2f06cd83?source=rss-1609bae59299------2"><img src="https://cdn-images-1.medium.com/max/811/1*SlRJajczrzTPZtmhTfKDxw.png" width="811"></a></p><p class="medium-feed-snippet">Qbot, also known as &quot;QakBot,&#x201D; is malware originally designed as a banking trojan to steal financial information.</p><p class="medium-feed-link"><a href="https://akshayprasad199503.medium.com/qbot-qakbot-malware-how-does-it-work-2a6a2f06cd83?source=rss-1609bae59299------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://akshayprasad199503.medium.com/qbot-qakbot-malware-how-does-it-work-2a6a2f06cd83?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a6a2f06cd83</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[qbot]]></category>
            <category><![CDATA[qakbot]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Sun, 21 Apr 2024 20:46:38 GMT</pubDate>
            <atom:updated>2024-04-21T20:46:38.379Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[TLS vs SSL: differences and weaknesses]]></title>
            <link>https://systemweakness.com/tls-vs-ssl-differences-and-weaknesses-40eb7000d961?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/40eb7000d961</guid>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[heartbleed]]></category>
            <category><![CDATA[ssl]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Fri, 29 Mar 2024 08:57:18 GMT</pubDate>
            <atom:updated>2024-04-21T20:44:37.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*Rely7XPs3gDsBIJlnCFR3A.png" /></figure><p>In today’s digitally interconnected world, maintaining secure communication between users and websites is crucial. The primary technologies that enable secure communication are SSL (Secure Socket Layer) and TLS (Transport Layer Security). SSL and TLS are cryptographic protocols that encrypt data sent over the internet, protecting sensitive information from unauthorised access. In this blog, we will look into the basic differences between TLS and SSL.</p><p>SSL and TLS are protocols for secure internet communication. TLS is the successor of SSL, which means SSL came way before TLS, and TLS was intended to address some of SSL&#39;s vulnerabilities and weaknesses.</p><h4>The basic key differences between SSL and TLS are as follows:</h4><p>1. <strong>Encryption</strong></p><blockquote>TLS uses strong encryption algorithms such as <strong>3DES</strong> or <strong>AES</strong>, whereas SSL uses 128-bit encryption, which is inferior to what TLS provides.</blockquote><p>2. <strong>Compatibility</strong></p><blockquote>TLS is the successor to SSL, and it is compatible with systems that previously supported SSL. SSL, on the other hand, cannot communicate with or work with TLS-enabled systems. <br> 1. As a result, upgrading to TLS is an excellent choice. Also, tls v1.3 is a good option, as tls1.0 and tls1.1 have already reached the end of the life.</blockquote><p><strong>3. Certificate verification</strong></p><blockquote>SSL and TLS verify certificate authenticity using different methods. SSL only checks that the certificate is signed by a trusted certificate authority, whereas TLS checks that the certificate is not expired, has not been revoked, and matches the requested domain name.</blockquote><p>4. <strong>Handshake Process</strong></p><blockquote>The handshake process for establishing a secure connection varies slightly between SSL and TLS, with TLS having more robust key exchange algorithms.</blockquote><p>5. <strong>Cipher Suites</strong></p><blockquote>TLS supports newer and stronger cipher suites than SSL, providing better encryption and authentication methods.</blockquote><h4><strong>Note:</strong></h4><blockquote><strong>Security:</strong></blockquote><p>TLS is widely believed to be more secure than SSL. SSL has known vulnerabilities, including <strong><em>POODLE</em></strong> and <strong><em>Heartbleed</em></strong>, which have been exploited in the past. TLS has better security features and is less prone to attacks.</p><p><strong>Some of the vulnerabilities are as follows:</strong></p><ol><li><strong>Heartbleed Bug</strong></li></ol><blockquote>The Heartbleed bug allows anyone on the Internet to read the memory of systems that are protected by vulnerable OpenSSL software. This compromises the secret keys used to identify service providers and encrypt traffic, as well as the users’ names, passwords, and content.</blockquote><blockquote><strong>More information:</strong> <a href="https://heartbleed.com/#:~:text=The%20Heartbleed%20bug%20allows%20anyone,users%20and%20the%20actual%20content.">Heartbleed bug</a>, <a href="https://medium.com/@tusharcool118/heartbleed-simple-yet-dangerous-b0ce9b08560c">simple yet dangerous</a></blockquote><p>2. <strong>POODLE</strong></p><blockquote>POODLE stands for “Padding Oracle On Downgraded Legacy Encryption”. In this vulnerability, an attacker is Man-in-the-Middle (MiTM) first.</blockquote><blockquote>Downgrade the TLS connection to SSLv3.<br>If the cypher suite employs an RC4 or Block cypher in CBC mode, the attacker can retrieve partial bytes of encrypted text and later obtain full plain text.</blockquote><blockquote><strong>More information</strong>: <a href="https://medium.com/@c0D3M/poodle-attack-explained-ed6a1cd0667d">POODLE Attack Explained</a>, <a href="https://nvd.nist.gov/vuln/detail/cve-2014-3566">CVE-2014–3566 — NVD</a></blockquote><p><strong>Conclusion:</strong></p><blockquote>To summarise, TLS is a newer and more secure protocol than SSL, featuring stronger encryption algorithms and improved certificate verification. For secure internet communication, it is recommended to use TLS rather than SSL.</blockquote><p>#cybersecurity #TLS #SSL #heartbleed #openssl #POODLE #vulnerabilites</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40eb7000d961" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/tls-vs-ssl-differences-and-weaknesses-40eb7000d961">TLS vs SSL: differences and weaknesses</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Cyber Kill Chain and the stages]]></title>
            <link>https://akshayprasad199503.medium.com/the-cyber-kill-chain-and-the-stages-90ab74bb5e77?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/90ab74bb5e77</guid>
            <category><![CDATA[cyber-kill-chain]]></category>
            <category><![CDATA[cyberattack]]></category>
            <category><![CDATA[blue-team]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Wed, 28 Dec 2022 22:29:49 GMT</pubDate>
            <atom:updated>2022-12-28T22:47:19.216Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*vEYBYQbbM-YUr2KJ0jCULA.jpeg" /></figure><p>A military concept known as “kill chain” describes the organization of an attack. It consists of identifying the target, sending forces there, launching an attack on the target, and destroying the target. On the other hand, “breaking” an opponent’s kill chain is a defensive or proactive strategy.</p><blockquote><strong>Stage 1: Reconnaissance</strong></blockquote><p>This is a stage, where an adversary tries to gather as many information as possible by investigating the flaws in the <strong>network</strong>, vulnerabilities which can be exploited, et cetera.</p><p>For example:</p><ul><li>Attacker might get to know about the user names, userIDs</li><li>Softwares that are running in the system and the corresponding programmes.</li></ul><blockquote><strong>Stage 2: Weaponisation</strong></blockquote><p>The weaponisation stage of the cyber kill chain involves developing a backdoor and a penetration plan using the information gathered from reconnaissance to successfully deliver the backdoor</p><p>Example:</p><ul><li><strong>Malware: </strong>A system or network is infected with malicious software to carry out tasks the owner does not want done. Examples include worms, viruses, et cetera.</li><li><strong>DDOS: </strong>Distributed denial of service attack, where the system will be hit consistently with loads of traffic where the availability of the system will be gone(system breakdown).</li></ul><blockquote><strong>Stage 3: Delivery</strong></blockquote><p>Attackers/Adversaries then use a medium like <strong>phishing emails</strong> or network or system hacking to deliver the attack vector to their target. This is the point where the attacker formally launches an attack against a target, regardless of the kind of attack they intend to launch.</p><p>Example:</p><ul><li>Email attachments</li><li>Phishing attempts (To deliver the malwares)</li><li>Abusing the open ports and exploiting it.</li><li>Drive-by Downloads(<a href="https://www.kaspersky.com/resource-center/definitions/drive-by-download">More details</a>): Adversary loads the malicious advertisements in the browsers.</li></ul><blockquote><strong>Stage 4: Exploitation</strong></blockquote><p>Executing the exploit with the goal of silently installing and executing the payload comes after the cyber weapon has been shipped.</p><p>Only outdated systems will be affected by the exploit, which is likely to go undetected by firewalls and antivirus software.</p><p>Example:</p><ul><li>Old operating system where the updates are not installed/patched.<br>Example list can found <a href="https://www.cisa.gov/uscert/ncas/alerts/aa22-117a"><strong><em>here</em></strong></a></li></ul><blockquote><strong>Stage 5: Installation</strong></blockquote><p>Sometimes this stage is also known as <strong><em>Privilege escalation phase. </em></strong>The adversary installs the malware that was delivered to the system in order to gain the control of the system or could be any particular account.</p><p>Examples:</p><ul><li><strong>Installing</strong> <strong>backdoors: </strong>A type of malware known as a backdoor circumvents standard authentication procedures to gain access to a system. As a result, resources within an application, like databases and file servers, are accessible remotely, giving offenders the ability to remotely execute commands on the system and update malware.</li><li><strong>Trojan horse: </strong>A Trojan Horse Virus is a form of malware that installs itself on a computer by impersonating a trustworthy application. The delivery technique typically involves an attacker hiding malicious code in legitimate software using <strong><em>social engineering(ex: phishing)</em></strong> in an effort to gain users’ system access.</li></ul><blockquote><strong>Stage 6: Command and Control(C&amp;C)</strong></blockquote><p>In my opinion every cyber attack must include the C&amp;C server, which transmits remote, secret instructions to compromised computers. It serves as the location for exfiltrating the data as well. The design of C&amp;C networks has advanced significantly over time as a result of the rapid development of defense mechanisms like antivirus software, firewalls, intrusion detection systems, etc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*A9PTqHHUdAtCh3ZHxundCQ.png" /></figure><p>Also it includes such as <strong><em>ransomware, DNS hijacking et cetara. </em></strong>Main way of preventing probably is to apply DNS filtering tools (<a href="https://cybersecuritynews.com/dns-filtering-solutions/">Example tools are here</a>)</p><p><strong>Important</strong>: During this phase attacker makes this traffic very much genuine/false positive as it often comprises of encrypted data/communication et cetera.</p><blockquote><strong>Stage 7: Action/Act</strong></blockquote><p>Action is the means by which the intruder achieves his main aim.<br>The attacker’s ultimate objective could be anything from demanding a ransom from you in return for file decryption to stealing customer data from the network. Data-loss prevention tools can halt exfiltration in the latter case before the data leaves your network. In other attacks, endpoint agent software is able to spot activity that differs from predefined baselines and alert IT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NtYSnju82fx8NW_Ya2W6Zg.png" /><figcaption>The files are locked due to ransomware.</figcaption></figure><blockquote><strong>Conclusion:</strong></blockquote><p>The article’s main goal was to explain the various steps in the cyber kill chain and the strategies used by adversaries to infiltrate systems and accomplish their objectives. We are quickly moving toward an extremely digitalized world, so it is crucial to be careful with our network and understand how we can be taken advantage of.</p><p><strong>Concluding with the following tip:</strong></p><blockquote><strong>Passwords are like underwear. Don’t let people see it, change it very often, and you shouldn’t share it with strangers ~ “</strong><em>Chris Pirillo</em><strong>”</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90ab74bb5e77" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSH and it’s working]]></title>
            <link>https://akshayprasad199503.medium.com/ssh-and-its-working-375aa4a7671c?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/375aa4a7671c</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 15:27:13 GMT</pubDate>
            <atom:updated>2022-12-24T15:48:40.191Z</atom:updated>
            <content:encoded><![CDATA[<p>SSh is a shorthand for <strong><em>Secured Shell</em></strong>, which follows a <strong><em>client-server</em></strong> architecture.</p><p>In the world of computers, where they talk to each other and share data, SSH helps to do it securely (<strong>strong encryption</strong>).</p><blockquote><strong>Why do we need SSH in the first place?</strong></blockquote><p>When we think of a secure way, we think of bad actors and their methods of exploitation. If we do not secure the data and its transmission, we can expect data theft, man-in-the-middle attacks, and so on.</p><p>Before SSH, there were other protocols such as Telnet, rlogin, and so on, but they were not secure.</p><p>Telnet, for example, sends and receives data in plain text that is not encrypted (secured). In the networking world, where several computers are linked together, data transmission may have to pass through several hops/computers before reaching its final destination. As a result, data can be stolen, intercepted, and so on. As a result, SSH is regarded as one of the most secure methods of communicating between clients and remote machines.</p><blockquote><strong>It works in the following ways:</strong></blockquote><p>As previously stated, it is a client-server protocol used for secure/encrypted communication. It communicates through standard port 22.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*RXEeOaTr2GxKLI50J5FavA.png" /></figure><p>There are two types of cryptography: <strong>symmetric encryption</strong> (<strong><em>private key encryption</em></strong>) and <strong>asymmetric encryption</strong> (<strong><em>public key encryption</em></strong>).<br>To authenticate between the client and the remote server, SSH employs public key cryptography. However, the protocol employs symmetric encryption and hashing techniques to exchange messages.</p><blockquote><strong>Before data exchange begins, SSH performs several important steps, including:</strong></blockquote><ul><li>Server verification</li><li>Authentication</li><li>Accessing using SSH command</li></ul><ol><li><strong>Server verification:</strong></li></ol><p>It is most likely a straightforward one in which the client initiated the SSH connection to TCP port 22. If the client is being seen for the first time, the client must manually provide the public key.</p><pre>ls -l ~/ssh/<br># Here, the keys must be preset and they will be like id_rsa and id_rsa.pub</pre><p>To create a new one, follow the below steps:</p><pre>mkdir ~/.ssh #create a directory if it is not existing<br><br>Chmod 700 ~/.ssh #change the permission<br><br>ssh-keygen #Key generation command<br><br>#Enter the file name to save the key pair<br>#IMPORTANT: enter the passphrase <br>#On the screen you will see where the keys are stored.</pre><p><strong>2. Authentication:</strong></p><p>Authentication is done by generating SSH key Pairs. It generates two keys to serve two different circumstances in which one is a public key and the other is the private key as mentioned above.</p><ul><li><strong>Public key:</strong> used for encryption of data that can be shared with others.</li><li><strong>Private key:</strong> used to decrypt the data and only the owner will have it(Not for public purposes)</li></ul><p><strong>3. Accessing via SSH command:</strong></p><p><strong>Mac/Linux users: </strong>can directly access via the command line</p><p>Windows users: May have to use Putty(<a href="https://www.putty.org/">D</a>ownload here) which is the most popular ssh client for windows.</p><p><strong>Use the following command:</strong></p><pre>ssh &lt;username&gt;@&lt;host&gt; -p &lt;port&gt;<br><br>#Username: It is not the local system name but it is name of the remote server that we are trying to connect/access<br>#host: usually it will be either the domain name or the IP address<br>#Port: it is by default 22 but it can be changed as well for better security<br><br><br>#Example command:<br>ssh mylab@mylab.xyz -p 3200<br><br>#It will prompt for the username and the password</pre><blockquote><strong>Things/Tips to remember:</strong></blockquote><ul><li>Generate a key with larger bits which is strong for security</li></ul><p>Example: <strong><em>ssh-keygen -b 4096</em></strong></p><ul><li>Changing the passphrase:</li></ul><p><strong><em>ssh-keygen -p</em></strong></p><ul><li>Display the SSH Key fingerprint:</li></ul><p><strong><em>ssh-keygen -l</em></strong></p><blockquote><strong>Conclusion:</strong></blockquote><p>The idea was to give a rough overview of SSH works and why it is necessary for the modern days. In addition, how it can be accessed along with some tips to remember the keys, especially for Mac and Linux users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=375aa4a7671c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leadership styles and Management]]></title>
            <link>https://akshayprasad199503.medium.com/leadership-styles-and-management-44ef950d811e?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/44ef950d811e</guid>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Mon, 12 Jul 2021 11:24:58 GMT</pubDate>
            <atom:updated>2024-04-21T20:45:17.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6VrS1pppOrE0TBPRFrchQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*XWWVMtqJSPtVg6unEQed8g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*spsfnkAs2YQg4bZNbj0W9g.png" /></figure><h3><strong>What is a leadership style?</strong></h3><p>A leader’s leadership style describes how he or she directs, motivates, guides, and manages groups of people. Political movements and social change can be inspired by great leaders. They can also inspire others to excel, create, and innovate.</p><p>When you consider some of the people you consider to be great leaders, you will notice that there are often significant differences in how each person leads. Fortunately, researchers have developed various theories and frameworks that help us better identify and comprehend these different leadership styles.</p><p>The different types of leadership I have come across and applied are as follows:</p><ol><li>Transformational Leadership.</li><li>Transactional Leadership.</li><li>Authoritarian Leadership.</li><li>Participative Leadership.</li><li>Delegative Leadership.</li><li>Charismatic Leadership.</li></ol><p><strong>Transformational Leadership</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*W_ZCXg5yZ1TgvwC2RJq_tQ.png" /></figure><p>The leader in transformational leadership inspires his or her followers with a vision and then encourages and empowers them to achieve it. The vision’s leader also serves as a role model.</p><p>Transformational leaders inspire and educate by sharing a common vision of the future. They communicate effectively. They motivate their team by expecting the best from everyone and holding themselves accountable as well. Transformational leaders typically exhibit the following characteristics:</p><blockquote>Integrity</blockquote><blockquote>Self-awareness</blockquote><blockquote>Authenticity</blockquote><blockquote>Empathy</blockquote><p><strong>Transactional Leadership</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*fhOC_0zf4stoaYz9f1F1Dw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*02eRasQ9CdNNKa3Up_Toew.png" /></figure><p>Transactional leadership styles rely on “<strong>transactions</strong>” — rewards, punishments, and other exchanges — between a leader and his or her followers to get the job done. The leader establishes clear objectives, and team members understand how they will be rewarded for their cooperation. This “<strong>give and take</strong>” leadership style is more concerned with efficiently carrying out established routines and procedures than with bringing about transformational changes in an organization.</p><p>Members of a group may also be motivated to perform well to receive rewards. One of the most significant disadvantages of the transactional style is that it tends to stifle creativity and out-of-the-box thinking.</p><p><strong>Authoritarian Leadership</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*pkEP7QIgMjaupCzFO9hcHw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*Wp3Io88g_TDVXmwFdGMEWg.png" /></figure><p>Authoritarian or autocratic leaders set explicit expectations for what must be done when it must be done, and how it must be done. This leadership style places a great emphasis on both the leader’s command and the followers’ control. A significant distinction exists between the leader and the members. Authoritarian leaders make choices on their own, with little or no involvement from the rest of the group.</p><p>Employee feedback is not taken into account under this sort of leadership, which limits their originality and innovation. Furthermore, because the boss is in the spotlight rather than the employees, the collaboration between them will be decreased. On the other side, this leadership style consistently produces excellent results.</p><p><strong>Participative Leadership</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*d0VxQCM3JlNG2s5S7DQBzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*62psv3ZVVz8MNkgu3Csevg.jpeg" /></figure><p>Democratic ideology underpins participatory leadership styles. The goal is to have team members participate in decision-making. As a result, team members feel included, engaged, and inspired to participate. In most decision-making processes, the leader will have the final say. When there are conflicts within a group, however, reaching a consensus can be a lengthy process.</p><p>Employees will always feel included, motivated, and have a high level of job satisfaction under this leadership style. This will boost the team’s creativity while also increasing productivity.<br>The downsides, on the other hand, are that because so many people are involved in the process, decision-making will always take time. Communication can also go wrong at times.</p><p><strong>Delegative Leadership(Laissez-Faire leadership)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*c-pnEBJQaiIqhF5clIcriA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cm9yO2UarkRFcQXgtuNrgg.png" /></figure><p>A delegation leadership style, often known as “<strong>laissez-faire leadership</strong>,” emphasizes delegating initiative to team members. If team members are skilled, take responsibility, and want to work alone, this can be an effective technique. Disagreements among members, on the other hand, can break and divide a group, resulting in low motivation and morale.</p><p>The benefit of such leadership is that innovation and creativity are constantly recognized here, with senior employees utilizing their knowledge and expertise. On the other side, this leadership style has a hard time adapting to changes that occur.</p><p><strong>Charismatic Leadership</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*bb33e91Du6Gyxgh30JrXRg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*GKSGVsmmhq8thZqQkPKKfA.png" /></figure><p>Charismatic leaders are those who can walk the talk. This style’s leaders are experts of communication and persuasion with a charming demeanour. They possess a certain charm, attractiveness, and magnetism. It aids them in persuading others to follow their lead. They motivate, excite, and enthuse the members of the team.</p><p>The Dalai Lama and Gouthama Buddha are two charismatic leaders that come to mind. When they walk into a room, they emanate warmth and presence. It’s what they refer to as the aura!</p><p>Some people are charismatic from birth, while others develop it over time and experience and this is one of my favourite types of leadership.</p><p>Charismatic leaders are self-assured in their approach. They rarely have second thoughts about their choices and have a powerful personalities.<br>They can sway a vast number of people.<br>They energise employees’ motivations and have faith in their abilities.<br>They set high standards for themselves and their staff, and they serve as role models for them.</p><p><strong>The gist of the overall leadership keeping followers in the picture.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ylzE9tNGtDckdZs-zYZMoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*PuGTU10nvjPjClMyUyA6VQ.png" /></figure><p><strong>Conclusion</strong></p><p>In my experience, I’ve learned that being a successful leader, as well as being ambitious, requires compassion and understanding. I gained a viewpoint on being a leader and how to achieve/approach the aim of being compassionate toward people through the books, workshops and various seminars.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44ef950d811e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[sample-registrationPage-bootstrap]]></title>
            <link>https://akshayprasad199503.medium.com/sample-registrationpage-bootstrap-1c39d840f4f0?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c39d840f4f0</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[bootstrapping]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Sun, 25 Apr 2021 08:38:29 GMT</pubDate>
            <atom:updated>2021-05-20T00:14:19.721Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUrijK1mmuh1fVPHhzQguA.png" /></figure><p>This article contains a sample user registration page using bootstrap.</p><p>The link to the article can be found here:</p><p>https://github.com/akshayprasad/sample-registrationPage-bootstrap</p><h3>steps to access:</h3><ul><li>Download the sample given above</li><li>Run the <strong>index.html</strong> file using the local path.</li></ul><h3>Page View:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2TNZgJm3wtUqbN8TO-d-Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c39d840f4f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Karma-Jasmine]]></title>
            <link>https://akshayprasad199503.medium.com/karma-jasmine-64ed403c5491?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/64ed403c5491</guid>
            <category><![CDATA[jasmine]]></category>
            <category><![CDATA[angularjs]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Sat, 24 Apr 2021 22:27:08 GMT</pubDate>
            <atom:updated>2021-04-24T22:34:24.607Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*tAGJzmAdyQGGNJkQ1tyAdw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4laFk6-D-wOAeu6TYNmfvQ.png" /></figure><h3>Quick Start?</h3><pre>$ git clone <a href="https://github.com/akshayprasad/Karma-Jasmine.git">https://github.com/akshayprasad/Karma-Jasmine.git</a></pre><p>To run the sample, open a command prompt and execute the following commands:</p><ul><li><strong>npm install</strong> (to install karma package)</li><li><strong>npm install -g gulp</strong> (to install gulp globally)</li><li><strong>npm install -g karma-cli </strong>(to install karma CLI globally)</li><li><strong>bower install</strong> (to install front-end packages)</li><li><strong>gulp test</strong> (to start karma and run tests / Run test once and exit)</li><li><strong>gulp dev-test</strong> (to start karma and run tests / Watch for file changes and re-run tests on each change)</li><li><strong>npm test </strong>(to start karma and run tests / Watch for file changes and re-run tests on each change)</li></ul><h3>About Unit Testing:</h3><p>The primary goal of unit testing is to take the smallest piece of testable software in the application, isolate it from the remaining of the code, and determine whether it behaves perfectly as you expect.</p><h3>Testing AngularJS Application :</h3><p>AngularJS build around the concept of dependency injection &amp; loose coupling to the DOM which make it testable.</p><p>Test-Driven Development: Test-Driven Development a software development process that relies on the repetition of a short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the fair amount of code to pass that test, and lastly refractors the new code to acceptable standards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*IQ9iupkqs-bNzR5MO-iOCg.jpeg" /></figure><h3>AngularJS</h3><p>AngularJS is one of the most popular single-page application frameworks.</p><h3>Why Karma?</h3><p>Karma is a javascript command-line tool that used to spawn a web server that loads your application.</p><p>The main goal for Karma is to bring a productive testing environment to developers. The environment is one where they don’t have to set up loads of configurations, but rather a place where developers can write the code and get instant feedback from their tests. Because getting quick feedback is what makes you productive and creative.</p><p><a href="http://karma-runner.github.io/">http://karma-runner.github.io</a></p><h3>Why Jasmine?</h3><p>Jasmine is an open-source behaviour-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can simplify writing tests.</p><ul><li>Jasmine provides functions to help with structuring your tests and also making assertions.</li></ul><p>For more details go to the following link:</p><p>https://github.com/vishwackh/AngularJS-Jasmine-Karma/wiki/About-Jasmine</p><p><a href="http://jasmine.github.io/">http://jasmine.github.io</a></p><h3>Why ANGULAR MOCKS?</h3><p>ANGULAR MOCKS Allows you to inject and mock Angular services for unit tests.</p><p><a href="https://docs.angularjs.org/guide/unit-testing">https://docs.angularjs.org/guide/unit-testing</a></p><h3>Project Setup:</h3><p>— Setting up our TDD Environment Project Setup —</p><ul><li>Let`s start writing from scratch. First, we need to create a basic project structure with a folder that contains our sources, and a folder that contains our specs. then we can init a package.json using the command $npm init</li><li>$ <strong>npm install karma</strong> let`s install Karma (and all the plugins your project needs) locally in the project’s directory. (don`t forget to use the — save-dev flags)</li><li>$ <strong>npm install karma-jasmine</strong> $ npm install karma-chrome-launcher since we going to use jasmine, let`s install the karma adaptor plugin for jasmine. we will also install the chrome launcher plugin to enable karma to launch chrome browser for us.</li><li>$ <strong>npm install -g karma-cli</strong>, we will install the karma command-line interface (CLI) globally, which enable us to simplify and configure karma in our project</li><li>$ <strong>karma init</strong> with the karma CLI installed, we can create our configuration file fast and easy.</li><li>$ <strong>karma start</strong> $ <strong>karma run</strong> Let`s take karma for a test drive: in web storm, right-click on the configuration file and choose Run. if you don`t use the web store, start the karma server with start, and run your tests with run (karma start/karma start karma.conf.js)</li></ul><h3>a quick introduction to the Jasmine framework Jasmine</h3><p>In jasmine, we begin by creating a test suite with the global describe function that wrap our specs. specs defined by the global function it. inside the spec, we can describe our expectations by using the expect function chained to a matcher function</p><pre>describe(&quot;suite name&quot;, function() {</pre><pre>	it(&quot;contains spec with an expectation&quot;, function() {<br>	   expect(true).toBe(true);<br>	});</pre><pre>});</pre><p>we can run code before and after each spec in a suite block using the beforeEach and afterEach functions</p><pre>describe(&quot;suite name&quot;, function() {</pre><pre>  beforeEach(function () { /*excute before each spec*/ })</pre><pre>  it(&quot;contains spec with an expectation&quot;, function() {<br>    expect(true).toBe(true);<br>  });</pre><pre> afterEach(function () { /*excute after each spec */ }) });</pre><p>jasmine use spies to track calls to a function with all its arguments. The toHaveBeenCalled and The toHaveBeenCalledWith special matchers for interacting with spies.</p><pre>// spy on the method setBar of foo object</pre><pre>spyOn(foo, &#39;setBar&#39;);</pre><pre>    it(&quot;contains spec with an expectation&quot;, function() {<br>   	 expect(foo.setBar).toHaveBeenCalled();<br>   	 expect(foo.setBar).toHaveBeenCalledWith(32);<br>    });<br>});</pre><h3>Testing AngularJS</h3><h3>Test-Driven Development in practice</h3><p>We are going to develop a small app. in the process we will learn how to unit test the building blocks of every AngularJS application: controllers, services, directives, events &amp; HTTP requests. First, let`s get some resources using bower</p><pre>$ bower install angular<br>$ bower install angular-mocks</pre><h3>Controller</h3><p>To test controllers we need to hold an instance of the controller, initialize a scope for it and testing our expectations against that scope.</p><pre>// get the module that contain the controller<br> beforeEach(module(&#39;appmodule&#39;));<br> // inject the $controller and the rootScope<br> beforeEach(inject(function ($rootScope, $controller) {<br>   // create a fresh new scope for the controller<br>  scope = $rootScope.$new();<br>  // create a controller with this scope<br>  ctrl = $controller(&#39;appController&#39;,{$scope: scope});<br> }));</pre><h3>Services</h3><p>To test services we need to use the $injector to get an instance of the service</p><pre>// get the module that contain the service<br>beforeEach(module(&#39;appmodule&#39;));<br>// inject the $injector<br>beforeEach(inject(function ($injector) {<br>  // use the $injector to get a hold on the service<br>  service = $injector.get(‘ServiceName’);<br>}));</pre><h3>Directive</h3><p>To test a directive, we need to create an element that will host the directive and compile it with a scope. in our spec, we need to trigger the digest.</p><pre>// get the module that contain the service<br>beforeEach(module(&#39;appmodule&#39;));<br>// inject the $compile service and the $rootScope<br>beforeEach(inject(function ($compile, $rootScope) {<br>  // use the $rootScope to create a scope for the directive<br>  scope = $rootScope;<br>  // create an angular element from a HTML string<br>  element = angular.element(‘&lt;div my-directive &gt;&lt;/div&gt;’)<br>  // compile the element with the scope<br>  $compile(element)(scope)<br>  scope.$apply()<br>}));</pre><h3>HTTP requests</h3><p>the $httpBackend is a fake HTTP Back-end implementation. in the most basic use we can verify that a request is made &amp; stub responses</p><pre>// inject the $httpBackend service and the $rootScope<br>beforeEach(inject(function ($httpBackend) {<br>	// use the $rootScope to create a scope for the directive<br>	httpBackend = $httpBackend;<br>	it(&quot;something that make a request&quot;, function() {<br>	// expect a request<br>	httpBackend.expectGET(‘api’).respond(200);<br>	// code that make a request<br>	httpBackend.flush(); // do`nt forget to flush..<br>	});<br>}));</pre><h3>Productive Tips</h3><p>— Making testing even easier —</p><p>When the number of test suites and specs grows larger, the overall test speed is affected. jasmine include some useful syntax to control it.</p><pre>// run this usite<br>	ddescribe()</pre><pre>	// run this spec<br>	iit()</pre><pre>	// skips this spec without executing.<br>	xit()</pre><pre>    // skips this block without executing.<br>	xdescribe()</pre><p>web store users can install the d<a href="http://plugins.jetbrains.com/plugin/7233?pr=idea">describer for jasmine</a>(<a href="https://plugins.jetbrains.com/plugin/7233-ddescriber-for-jasmine/">https://plugins.jetbrains.com/plugin/7233-ddescriber-for-jasmine/</a>)</p><h3>Sample Examples with explanation</h3><ul><li><a href="https://github.com/vishwackh/AngularJS-Jasmine-Karma/wiki">Check Examples</a> (<a href="https://github.com/vishwackh/AngularJS-Jasmine-Karma/wiki">https://github.com/vishwackh/AngularJS-Jasmine-Karma/wiki</a>)</li></ul><h3>Reference</h3><ul><li>Karma runs on Node.js and is available as an NPM package. Setup steps can be found with this link — <a href="http://karma-runner.github.io/0.12/intro/installation.html">http://karma-runner.github.io/0.12/intro/installation.html</a></li><li>The current test cases are constructed using the <a href="https://jasmine.github.io/">https://jasmine.github.io/</a> -Check the examples of the above-mentioned description.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64ed403c5491" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Basics]]></title>
            <link>https://akshayprasad199503.medium.com/python-basics-9b6a5145f251?source=rss-1609bae59299------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b6a5145f251</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Akshay Prasad]]></dc:creator>
            <pubDate>Sat, 24 Apr 2021 21:42:32 GMT</pubDate>
            <atom:updated>2021-04-24T21:42:32.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TJlQ1bWb114mQPobnxQt5w.jpeg" /></figure><h3>What is Python?</h3><p>Python is a very simple language and has a very straightforward syntax. It encourages programmers to program without prepared code. The simplest directive in Python is the “print” directive — it simply prints out a line.</p><p>There are two major Python versions, Python 2 and Python 3. Python 2 and 3 are quite different. This tutorial uses Python 3 because it more semantically correct and supports newer features.</p><p>To print a string in Python 3, just write: print(“This line will be printed.”);</p><h3>Indentation</h3><p>Python uses indentation for blocks, instead of curly braces. Both tabs and spaces are supported, but the standard indentation requires standard Python code to use four spaces</p><pre>if name == &#39;Python&#39;:<br>        print(name);</pre><h3>Variables and Types</h3><ul><li>Python is completely object-oriented, and not “statically typed”.</li><li>No need to declare variables before using them or declare their type.</li><li>Every variable in Python is an object.</li></ul><h3>Numbers</h3><p>Python supports two types and they are:</p><ol><li>Integer</li><li>Floating</li></ol><pre>Integer:<br><br>intergerValue = 10;<br>print(integerValue); //Outputs 10<br><br>floatValue = float(integerValue);<br>print(floatValue); //Outputs 10.0</pre><h3>Strings</h3><p>Strings can be defined either in a double quote or a single quote.</p><pre>stringValueSingleQuote = &#39;python&#39;;<br>stringValueDoubleQuote = &quot;python&quot;;</pre><pre>print(stringValueSingleQuote) //outputs python<br>print(stringValueDoubleQuote) //outputs python</pre><pre>one = 1<br>two = 2<br>three = one + two<br>print(three) //outputs 3<br><br>hello = &quot;hello&quot;<br>world = &quot;world&quot;<br>helloworld = hello + &quot; &quot; + world<br>print(helloworld) //outputs hello world</pre><p>There are additional variations on defining strings that make it easier to include things such as carriage returns, backslashes and Unicode characters. <a href="https://docs.python.org/3/tutorial/introduction.html#strings">https://docs.python.org/3/tutorial/introduction.html#strings</a></p><h4>Operator assignment</h4><p>Assignments can be done on more than one variable “simultaneously” on the same line like this:</p><pre>a,b = 2,4;<br>print(a,b) //outputs 2,4.</pre><h3>Lists</h3><p>Lists are very similar to arrays. They can contain any type of variable, and they can contain as many variables as you wish. Lists can also be iterated over in a very simple manner. Here is an example of how to build a list.</p><pre>listVariable = []<br>listVariable.append(1)<br>listVariable.append(2)<br>listVariable.append(3)<br>print(listVariable[0]) # prints 1<br>print(listVariable[1]) # prints 2<br>print(listVariable[2]) # prints 3</pre><pre># prints out 1,2,3<br>for x in listVariable:<br>    print(x)</pre><pre>//outputs 1 2 and 3 in a seperate line.</pre><h3>Basic operators</h3><p>Just as any other programming languages, the addition, subtraction, multiplication, and division operators can be used with numbers.</p><pre>print(1+2+3/3) //Outputs 2.<br><br>remainder = 11 % 3<br>print(remainder) //Outputs 2<br><br>squared = 7 ** 2<br>cubed = 2 ** 3<br><br>print(squared) //outputs 49<br>print(cubed); //ouputs 8</pre><h3>using operators with a string</h3><pre>helloworld = &quot;hello&quot; + &quot; &quot; + &quot;world&quot;<br>print(helloworld) //outputs hello world</pre><pre>surprisehellos = &quot;hello&quot; * 10<br>print(surprisehellos) //outputs hellohellohellohellohellohellohellohellohellohello</pre><h3>using operators with Lists</h3><pre>even = [2,4,6,8]<br>odd = [1,3,5,7]<br>allNumbers = odd + even<br>print(allNumbers) //outputs [1, 3, 5, 7, 2, 4, 6, 8]</pre><pre>print([5,6] * 3) //outputs [5, 6, 5, 6, 5, 6]</pre><h3>String Formatting</h3><p>Python uses C-style string formatting to create new, formatted strings. The “%” operator is used to format a set of variables enclosed in a “tuple” (a fixed-size list), together with a format string, which contains normal text together with “argument specifiers”, special symbols like “%s” and “%d”.</p><pre>name = &quot;python&quot;<br>print(&quot;World of, %s!&quot; % name) //Outputs World of python<br><br>name = &quot;python&quot;<br>version = 3.5.1<br>print(&quot;%s latest version is %f&quot; % (name, version)) //Outputs python latest version is 3.5.1</pre><p>The list can be also be represented using %s, basically, an object which is not a string can be formatted using the %s operator as well.</p><pre>listVariable = [1,2,3]<br>print(&quot;A list: %s&quot; % listVariable) //Outputs [1,2,3]</pre><h3>Important formatters to be remembered</h3><ul><li><strong>%s </strong>— String (or any object with a string representation, like numbers)</li><li><strong>%d </strong>— Integers</li><li><strong>%f</strong> — Floating point numbers</li><li><strong>%.f</strong> — Floating point numbers with a fixed amount of digits to the right of the dot.</li><li><strong>%x / %X</strong> — Integers in hex representation (lowercase/uppercase)</li></ul><h3>Basic String Operations</h3><p>Strings are bits of text. They can be defined as anything between quotes</p><p>The multiple methods(iun-built) for string are:</p><ul><li><strong>len()</strong></li><li><strong>index()</strong></li><li><strong>count()</strong></li><li><strong>upper()</strong></li><li><strong>lower()</strong></li><li><strong>startswith()</strong></li><li><strong>endswith()</strong></li><li><strong>split()</strong></li></ul><pre>stringVariable = &quot;python learning and knowing it&#39;s basic syntax.&quot;<br><br>print(len(stringVariable)) //Outputs 46<br><br>print(stringVariable.index(&#39;o&#39;)) //Outputs 4<br><br>print(stringVariable.count(&#39;o&#39;)) //outputs 2<br><br>print(stringVariable.upper()) //Outputs the string in uppercase<br><br>print(stringVariable.lower()) //Outputs the string in lowercase<br><br>print(stringVariable.startswith(&#39;python&#39;)) //Outputs True<br><br>print(stringVariable.endswith(&#39;syntax&#39;)) //Outputs True</pre><h3>Special list operations</h3><pre>stringVariable = &quot;Hello world!&quot;<br>print(stringVariable[3:7]) or print(stringVariable[3:7:1])//Outputs lo w</pre><pre>print(stringVariable[3:7:2]) //Outputs l</pre><pre>print(stringVariable[::-1]) //Ouputs !dlrow olleH</pre><pre>print(stringVariable.split(&quot; &quot;)) //Outputs [&#39;Hello&#39;, &#39;world!&#39;]</pre><h3>Conditions</h3><p>Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.</p><pre>x = 2<br>print(x == 2) # prints out True<br>print(x == 3) # prints out False<br>print(x &lt; 3) # prints out True</pre><h3>Boolean operators</h3><p>The “and” and “or” boolean operators allow building complex boolean expressions.</p><pre>name = &quot;John&quot;<br>age = 23<br>if name == &quot;John&quot; and age == 23:<br>    print(&quot;Your name is John, and you are also 23 years old.&quot;)</pre><pre>if name == &quot;John&quot; or name == &quot;Rick&quot;:<br>    print(&quot;Your name is either John or Rick.&quot;)</pre><h3>The “in” operator</h3><p>The “in” operator could be used to check if a specified object exists within an iterable object container, such as a list:</p><pre>name = &quot;John&quot;<br>if name in [&quot;John&quot;, &quot;Rick&quot;]:<br>    print(&quot;Your name is either John or Rick.&quot;)</pre><ul><li>Python uses indentation to define code blocks, instead of brackets.</li><li>The standard Python indentation is 4 spaces, although tabs and any other space size will work, as long as it is consistent.</li><li>Notice that code blocks do not need any termination.</li></ul><pre>if &lt;statement is=&quot;&quot; true=&quot;&quot;&gt;:<br>    &lt;do something=&quot;&quot;&gt;<br>    ....<br>    ....<br>elif &lt;another statement=&quot;&quot; is=&quot;&quot; true=&quot;&quot;&gt;: # else if<br>    &lt;do something=&quot;&quot; else=&quot;&quot;&gt;<br>    ....<br>    ....<br>else:<br>    &lt;do another=&quot;&quot; thing=&quot;&quot;&gt;<br>    ....<br>    ....<br>&lt;/do&gt;&lt;/do&gt;&lt;/another&gt;&lt;/do&gt;&lt;/statement&gt;</pre><p>Example:</p><pre>x = &#39;NA&#39;<br>if x == &#39;NA&#39;:<br>    print(&quot;x equals NA!&quot;)<br>else:<br>    print(&quot;x does not equal to NA.&quot;)</pre><p>A statement is evaluated as true if one of the following is correct:</p><ol><li>The “True” boolean variable is given or calculated using an expression, such as an arithmetic comparison.</li><li>An object which is not considered “empty” is passed.</li></ol><h3>The ‘is’ operator</h3><p>Unlike the double equals operator “==”, the “is” operator does not match the values of the variables, but the instances themselves.</p><pre>x = [3,4,5]<br>y = [3,4,5]<br>print(x == y) # Prints out True<br>print(x is y) # Prints out False</pre><h3>The “not” operator</h3><p>Using “not” before a boolean expression inverts it:</p><pre>print(not False) // Prints out True<br>print((not False) == (False)) // Prints out False</pre><h3>Loops</h3><p>There are two types of loops in Python, for and while.</p><h3>The “for” loop</h3><pre>odds = [1, 3, 5, 7]<br>for number in odds:<br>    print(number) //outputs 1 3 5 7 in a seperate line</pre><h3>range() vs xrange()</h3><ul><li>range() and xrange() are two functions that could be used to iterate a certain number of times in for loops in Python.</li><li>Note: In Python 3, there is no xrange, but the range function behaves like xrange in Python 2.</li><li>Note: If you want to write code that will run on both Python 2 and Python 3, you should use range().</li></ul><h3>range()</h3><p>This returns a list of numbers created using the range() function.</p><h3>xrange()</h3><p>This function returns the generator object that can be used to display numbers only by looping. The only particular range is displayed on demand and hence called “lazy evaluation“.</p><h3>Both are implemented in different ways and have different characteristics associated with them. The points of comparisons are:</h3><ul><li>Return Type</li><li>Memory</li><li>Operation Usage</li><li>Speed</li></ul><h3>Return Type</h3><ul><li>range() returns — the list as return type.</li><li>xrange() returns — xrange() object.</li></ul><pre># Python code to demonstrate range() vs xrange()<br># on basis of return type<br><br># initializing a with range()<br>a = range(1,10)<br><br># initializing a with xrange()<br>x = xrange(1,10000)<br><br># testing the type of a<br>print (&quot;The return type of range() is : &quot;)<br>print (a) //[1,2,3,4,5,6,7,8,9,10]<br><br># testing the type of x<br>print (&quot;The return type of xrange() is : &quot;)<br>print (x) //xrange(1, 10)</pre><h3>Example:</h3><pre>//Prints out the numbers 0,1,2,3,4<br>for x in range(5):<br>    print(x)</pre><pre>//Prints out 3,4,5<br>for x in range(3, 6):<br>    print(x)</pre><pre>//Prints out 3,5,7<br>for x in range(3, 8, 2):<br>    print(x)</pre><h3>“while” loops</h3><p>While loops repeat as long as a certain boolean condition is met.</p><pre>//prints out 0,1,2,3,4</pre><pre>count = 0<br>while count &lt; 5:<br>    print(count)<br>    count += 1  # This is the same as count = count + 1</pre><h3>“break” and “continue” statements</h3><h3>break</h3><p>is used to exit a for loop or a while loop</p><h3>continue</h3><p>is used to skip the current block</p><pre>//Prints out 0,1,2,3,4</pre><pre>count = 0<br>while True:<br>    print(count)<br>    count += 1<br>    if count &gt;= 5:<br>        break</pre><pre># Prints out only odd numbers - 1,3,5,7,9<br>for x in range(10):<br>    # Check if x is even<br>    if x % 2 == 0:<br>        continue<br>    print(x)</pre><h3>Important:</h3><h3>can we use the “else” clause for loops?</h3><p>unlike languages like C, CPP.. we can use else for loops. When the loop condition of the “for” or “while” statement fails then the code part in “else” is executed. If the break statement is executed inside for loop then the “else” part is skipped. Note that the “else” part is executed even if there is a continue statement.</p><h3>Example:</h3><pre>//Prints out 0,1,2,3,4 and then it prints &quot;count value reached 5&quot;</pre><pre>count=0<br>while(count&lt;5):<br>    print(count)<br>    count +=1<br>else:<br>    print(&quot;count value reached %d&quot; %(count))</pre><pre>//Prints out 1,2,3,4<br>for i in range(1, 10):<br>    if(i%5==0):<br>        break<br>    print(i)<br>else:<br>    print(&quot;this is not printed because for loop is terminated because of break but not due to fail in condition&quot;)</pre><h3>Functions</h3><h3>What are Functions?</h3><p>Functions are a convenient way to divide your code into useful blocks, allowing us to order our code, make it more readable, reuse it and save some time. Also, functions are a key way to define interfaces so programmers can share their code.</p><h3>How do you write functions in Python?</h3><p>Python makes use of blocks.</p><pre>block_head:<br>    1st block line<br>    2nd block line<br>    ...</pre><p>Where a block line is more Python code (even another block), and the blockhead is of the following format: block_keyword block_name(argument1,argument2, …) Block keywords you already know are “if”, “for”, and “while”.</p><h3>Functions in Python are defined using the block keyword “def”, followed by the function’s name as the block’s name.</h3><pre>def my_function():<br>    print(&quot;Hello From My Function!&quot;)</pre><pre>my_function() //prints Hello From My Function!</pre><h3>Import feature</h3><h3>Classes and Objects</h3><ul><li>Objects are an encapsulation of variables and functions into a single entity.</li><li>Objects get their variables and functions from classes. Classes are essentially a template to create your objects.</li></ul><h3>A very basic example is that:</h3><pre>class MyClass:<br>    variable = &quot;blah&quot;</pre><pre>    def function(self):<br>        print(&quot;This is a message inside the class.&quot;)</pre><p>Now the variable “myobjectx” holds an object of the class “MyClass” that contains the variable and the function defined within the class called “MyClass”.</p><h3>Accessing Object Variables</h3><pre>class MyClass:<br>    variable = &quot;blah&quot;</pre><pre>    def function(self):<br>        print(&quot;This is a message inside the class.&quot;)</pre><pre>myobjectx = MyClass()</pre><pre>print(myobjectx.variable) //prints blah</pre><p>You can create multiple different objects that are of the same class(have the same variables and functions defined). However, each object contains independent copies of the variables defined in the class.</p><pre>class MyClass:<br>    variable = &quot;blah&quot;</pre><pre>    def function(self):<br>        print(&quot;This is a message inside the class.&quot;)</pre><pre>myobjectx = MyClass()<br>myobjecty = MyClass()</pre><pre>myobjecty.variable = &quot;yackity&quot;</pre><pre># Then print out both values<br>print(myobjectx.variable) //prints blah<br>print(myobjecty.variable) //prints yackity</pre><h3>Dictionaries</h3><p>A dictionary is a data type similar to arrays but works with keys and values instead of indexes. Each value stored in a dictionary can be accessed using a key, which is any type of object (a string, a number, a list, etc.) instead of using its index to address it.</p><pre>phonebook = {}<br>phonebook[&quot;John&quot;] = 938477566<br>phonebook[&quot;Jack&quot;] = 938377264<br>phonebook[&quot;Jill&quot;] = 947662781<br>print(phonebook) </pre><pre>//Outputs {&#39;John&#39;: 938477566, &#39;Jack&#39;: 938377264, &#39;Jill&#39;: 947662781}</pre><p>Alternatively, a dictionary can be initialized with the same values in the following notation:</p><pre>phonebook = {<br>    &quot;John&quot; : 938477566,<br>    &quot;Jack&quot; : 938377264,<br>    &quot;Jill&quot; : 947662781<br>}<br>print(phonebook)</pre><pre>//Outputs {&#39;John&#39;: 938477566, &#39;Jack&#39;: 938377264, &#39;Jill&#39;: 947662781}</pre><h3>Iterating over dictionaries</h3><p>Dictionaries can be iterated over, just like a list. However, a dictionary, unlike a list, does not keep the order of the values stored in it. To iterate over key-value pairs, use the following syntax:</p><pre>phonebook = {&quot;John&quot; : 938477566,&quot;Jack&quot; : 938377264,&quot;Jill&quot; : 947662781}<br>for name, number in phonebook.items():<br>    print(&quot;Phone number of %s is %d&quot; % (name, number))</pre><pre>//outputs<br>//Phone number of John is 938477566<br>//Phone number of Jack is 938377264<br>//Phone number of Jill is 947662781</pre><h3>Removing a value</h3><p>To remove a specified index, use either one of the following notations:</p><pre>phonebook = {<br>   &quot;John&quot; : 938477566,<br>   &quot;Jack&quot; : 938377264,<br>   &quot;Jill&quot; : 947662781<br>}<br>del phonebook[&quot;John&quot;]<br>print(phonebook);</pre><pre>//oputputs {&#39;Jack&#39;: 938377264, &#39;Jill&#39;: 947662781}<br></pre><pre>phonebook = {<br>   &quot;John&quot; : 938477566,<br>   &quot;Jack&quot; : 938377264,<br>   &quot;Jill&quot; : 947662781<br>}<br>phonebook.pop(&quot;John&quot;)<br>print(phonebook)</pre><pre>//oputputs {&#39;Jack&#39;: 938377264, &#39;Jill&#39;: 947662781}</pre><h3>Modules and Packages</h3><p>In programming, a module is a piece of software that has a specific functionality. For example, when building a ping pong game, one module would be responsible for the game logic, and another module would be responsible for drawing the game on the screen. Each module is a different file, which can be edited separately.</p><h3>Exploring built-in modules</h3><p><a href="https://docs.python.org/3/library/">Check out the complete list of built-in modules in the python standard library.</a></p><h3>Two very important functions come in handy when exploring modules in Python:</h3><ul><li>dir</li><li>help</li></ul><p>We can look for which functions are implemented in each module by using the dir function:</p><pre>import urllib;<br>dir(urllib)</pre><pre>//Outputs<br>/* <br>[&#39;ContentTooShortError&#39;,<br> &#39;FancyURLopener&#39;,<br> &#39;MAXFTPCACHE&#39;,<br> &#39;URLopener&#39;,<br> &#39;__all__&#39;,<br> &#39;__builtins__&#39;,<br> &#39;__doc__&#39;,<br> &#39;__file__&#39;,<br> &#39;__name__&#39;,<br> &#39;__package__&#39;,<br> &#39;__version__&#39;,<br> &#39;_ftperrors&#39;,<br> &#39;_get_proxies&#39;,<br> &#39;_get_proxy_settings&#39;,<br> &#39;_have_ssl&#39;,<br> &#39;_hexdig&#39;,<br> &#39;_hextochr&#39;,<br> &#39;_hostprog&#39;,<br> &#39;_is_unicode&#39;,<br> &#39;_localhost&#39;,<br> &#39;_noheaders&#39;,<br> &#39;_nportprog&#39;,<br> &#39;_passwdprog&#39;,<br> &#39;_portprog&#39;,<br> &#39;_queryprog&#39;,<br> &#39;_safe_map&#39;,<br> &#39;_safe_quoters&#39;,<br> &#39;_tagprog&#39;,<br> &#39;_thishost&#39;,<br> &#39;_typeprog&#39;,<br> &#39;_urlopener&#39;,<br> &#39;_userprog&#39;,<br> &#39;_valueprog&#39;,<br> &#39;addbase&#39;,<br> &#39;addclosehook&#39;,<br> &#39;addinfo&#39;,<br> &#39;addinfourl&#39;,<br> &#39;always_safe&#39;,<br> &#39;basejoin&#39;,<br> &#39;c&#39;,<br> &#39;ftpcache&#39;,<br> &#39;ftperrors&#39;,<br> &#39;ftpwrapper&#39;,<br> &#39;getproxies&#39;,<br> &#39;getproxies_environment&#39;,<br> &#39;getproxies_macosx_sysconf&#39;,<br> &#39;i&#39;,<br> &#39;localhost&#39;,<br> &#39;main&#39;,<br> &#39;noheaders&#39;,<br> &#39;os&#39;,<br> &#39;pathname2url&#39;,<br> &#39;proxy_bypass&#39;,<br> &#39;proxy_bypass_environment&#39;,<br> &#39;proxy_bypass_macosx_sysconf&#39;,<br> &#39;quote&#39;,<br> &#39;quote_plus&#39;,<br> &#39;reporthook&#39;,<br> &#39;socket&#39;,<br> &#39;splitattr&#39;,<br> &#39;splithost&#39;,<br> &#39;splitnport&#39;,<br> &#39;splitpasswd&#39;,<br> &#39;splitport&#39;,<br> &#39;splitquery&#39;,<br> &#39;splittag&#39;,<br> &#39;splittype&#39;,<br> &#39;splituser&#39;,<br> &#39;splitvalue&#39;,<br> &#39;ssl&#39;,<br> &#39;string&#39;,<br> &#39;sys&#39;,<br> &#39;test&#39;,<br> &#39;test1&#39;,<br> &#39;thishost&#39;,<br> &#39;time&#39;,<br> &#39;toBytes&#39;,<br> &#39;unquote&#39;,<br> &#39;unquote_plus&#39;,<br> &#39;unwrap&#39;,<br> &#39;url2pathname&#39;,<br> &#39;urlcleanup&#39;,<br> &#39;urlencode&#39;,<br> &#39;urlopen&#39;,<br> &#39;urlretrieve&#39;]<br>*/</pre><h3>Numpy Arrays</h3><p>Numpy arrays are great alternatives to Python Lists. Some of the key advantages of Numpy arrays are that they are fast, easy to work with and allow users to perform calculations across entire arrays.</p><p>Example:</p><pre>//Create 2 new lists numbersOdd and numbersEven<br>numbersOdd = [1, 3, 5, 7]<br>numbersEven = [2,4,6,8]</pre><pre>//Import the numpy package as np<br>import numpy as np</pre><pre># Create 2 numpy arrays from height and weight<br>np_numbersOdd = np.array(numbersOdd)<br>np_numbersEven = np.array(numbersEven)</pre><pre>print(type(np_numbersEven))</pre><pre>Outputs:<br>&lt;class &#39;numpy.ndarray&#39;&gt;<br>&lt;class &#39;numpy.ndarray&#39;&gt;</pre><h3>Pandas Basics</h3><h3>Pandas DataFrames</h3><ul><li>Pandas is a high-level data manipulation tool developed by Wes McKinney.</li><li>It is built on the Numpy package and its key data structure is called the DataFrame.</li><li>DataFrames allow you to store and manipulate tabular data in rows of observations and columns of variables.</li></ul><h3>There are several ways to create a DataFrame. One way is to use a dictionary. For example:</h3><pre>dict = {&quot;country&quot;: [&quot;Brazil&quot;, &quot;Russia&quot;, &quot;India&quot;, &quot;China&quot;, &quot;South Africa&quot;],<br>       &quot;capital&quot;: [&quot;Brasilia&quot;, &quot;Moscow&quot;, &quot;New Dehli&quot;, &quot;Beijing&quot;, &quot;Pretoria&quot;],<br>       &quot;area&quot;: [8.516, 17.10, 3.286, 9.597, 1.221],<br>       &quot;population&quot;: [200.4, 143.5, 1252, 1357, 52.98] }</pre><pre>import pandas as pd<br>brics = pd.DataFrame(dict)<br>print(brics)</pre><pre>//Outputs<br>area    capital       country  population<br>0   8.516   Brasilia        Brazil      200.40<br>1  17.100     Moscow        Russia      143.50<br>2   3.286  New Dehli         India     1252.00<br>3   9.597    Beijing         China     1357.00<br>4   1.221   Pretoria  South Africa       52.98</pre><p>As you can see with the new BRICS DataFrame, Pandas has assigned a key for each country as the numerical values 0 through 4. If you would like to have different index values, say, the two-letter country code, you can do that easily as well.</p><pre>dict = {&quot;country&quot;: [&quot;Brazil&quot;, &quot;Russia&quot;, &quot;India&quot;, &quot;China&quot;, &quot;South Africa&quot;],<br>       &quot;capital&quot;: [&quot;Brasilia&quot;, &quot;Moscow&quot;, &quot;New Dehli&quot;, &quot;Beijing&quot;, &quot;Pretoria&quot;],<br>       &quot;area&quot;: [8.516, 17.10, 3.286, 9.597, 1.221],<br>       &quot;population&quot;: [200.4, 143.5, 1252, 1357, 52.98] }</pre><pre>import pandas as pd<br>brics = pd.DataFrame(dict)<br>brics.index = [&quot;BR&quot;, &quot;RU&quot;, &quot;IN&quot;, &quot;CH&quot;, &quot;SA&quot;]<br>print(brics)</pre><pre>//Outputs<br>      area    capital       country  population<br>BR   8.516   Brasilia        Brazil      200.40<br>RU  17.100     Moscow        Russia      143.50<br>IN   3.286  New Dehli         India     1252.00<br>CH   9.597    Beijing         China     1357.00<br>SA   1.221   Pretoria  South Africa       52.98</pre><h3>Generators</h3><p>Generators are very easy to implement, but a bit difficult to understand.</p><p>Generators are used to create iterators, but with a different approach. Generators are simple functions that return an iterable set of items, one at a time, in a special way.</p><p>When an iteration over a set of the item starts using the for statement, the generator is run. Once the generator’s function code reaches a “yield” statement, the generator yields its execution back to the for loop, returning a new value from the set. The generator function can generate as many values (possibly infinite) as it wants, yielding each one in its turn.</p><h3>Example:</h3><pre>import random</pre><pre>def lottery():<br>    # returns 6 numbers between 1 and 40<br>    for i in range(6):<br>        yield random.randint(1, 40)</pre><pre>    # returns a 7th number between 1 and 15<br>    yield random.randint(1,15)</pre><pre>for random_number in lottery():<br>       print(&quot;And the next number is... %d!&quot; %(random_number))<br></pre><pre>//Outputs<br>And the next number is... 33!<br>And the next number is... 17!<br>And the next number is... 11!<br>And the next number is... 17!<br>And the next number is... 10!<br>And the next number is... 15!<br>And the next number is... 2!</pre><h3>List Comprehensions</h3><p>List Comprehensions is a very powerful tool, which creates a new list based on another list, in a single, readable line.</p><p>For example, let’s say we need to create a list of integers that specify the length of each word in a certain sentence, but only if the word is not the word “the”.</p><h3>Before list comprehension:</h3><pre>sentence = &quot;the quick brown fox jumps over the lazy dog&quot;<br>words = sentence.split()<br>word_lengths = []<br>for word in words:<br>      if word != &quot;the&quot;:<br>          word_lengths.append(len(word))<br>print(words)</pre><pre>//outputs<br>[&#39;the&#39;, &#39;quick&#39;, &#39;brown&#39;, &#39;fox&#39;, &#39;jumps&#39;, &#39;over&#39;, &#39;the&#39;, &#39;lazy&#39;, &#39;dog&#39;]</pre><h3>After list comprehension:</h3><pre>sentence = &quot;the quick brown fox jumps over the lazy dog&quot;<br>words = sentence.split()<br>word_lengths = [len(word) for word in words if word != &quot;the&quot;]<br>print(words)</pre><pre>//outputs<br>[&#39;the&#39;, &#39;quick&#39;, &#39;brown&#39;, &#39;fox&#39;, &#39;jumps&#39;, &#39;over&#39;, &#39;the&#39;, &#39;lazy&#39;, &#39;dog&#39;]</pre><h3>Multiple Function Arguments</h3><p>Every function in Python receives a predefined number of arguments.</p><p>It is possible to declare functions that receive a variable number of arguments, using the following syntax:</p><pre>def foo(first, second, third, *therest):<br>    print(&quot;First: %s&quot; % first)<br>    print(&quot;Second: %s&quot; % second)<br>    print(&quot;Third: %s&quot; % third)<br>    print(&quot;And all the rest... %s&quot; % list(therest))<br>    <br>foo(1,2,3,4,5,6);</pre><pre>//outputs<br>First: 1<br>Second: 2<br>Third: 3<br>And all the rest... [4, 5, 6]</pre><p>It is also possible to send functions arguments by keyword so that the order of the argument does not matter, using the following syntax.</p><pre>def bar(first, second, third, **options):<br>    if options.get(&quot;action&quot;) == &quot;sum&quot;:<br>        print(&quot;The sum is: %d&quot; %(first + second + third))</pre><pre>    if options.get(&quot;number&quot;) == &quot;first&quot;:<br>        return first</pre><pre>result = bar(1, 2, 3, action = &quot;sum&quot;, number = &quot;first&quot;)<br>print(&quot;Result: %d&quot; %(result))</pre><pre>//outputs<br>The sum is: 6<br>Result: 1</pre><h3>Regular Expressions</h3><p>Regular Expressions (sometimes shortened to regexp, regex, or re) are a tool for matching patterns in text. In Python, we have the re module. The applications for regular expressions are widespread, but they are fairly complex, so when contemplating using a regex for a certain task, think about alternatives, and come to regexes as a last resort.</p><p>An example regex is r”^(From|To|Cc).*?python-list@python.org” Now for an explanation: the caret ^ matches text at the beginning of a line. The following group, the part with (From|To|Cc) means that the line has to start with one of the words that are separated by the pipe |. That is called the OR operator, and the regex will match if the line starts with any of the words in the group. The .*? means to un-greedily match any number of characters, except the newline \n character. The un-greedy part means to match as few repetitions as possible. The ‘.‘ character means any non-newline character, the * means to repeat 0 or more times, and the? character makes it un-greedy.</p><p>So, the following lines would be matched by that regex: From python-list@python.org To: !asp]&lt;,. python-list@python.org</p><p><a href="https://docs.python.org/3/library/re.html#regular-expression-syntax%22RE%20syntax">Click for a complete reference of the re syntax</a></p><p><a href="http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html">As an example of a “proper” email-matching regex, click here</a></p><pre># Exercise: make a regular expression that will match an email<br>import re<br>def test_email(your_pattern):<br>    pattern = re.compile(your_pattern)<br>    emails = [&quot;john@example.com&quot;, &quot;python-list@python.org&quot;, &quot;wha.t.`1an?ug{}ly@email.com&quot;]<br>    for email in emails:<br>        if not re.match(pattern, email):<br>            print(&quot;You failed to match %s&quot; % (email))<br>        elif not your_pattern:<br>            print(&quot;Forgot to enter a pattern!&quot;)<br>        else:<br>            print(&quot;Pass&quot;)<br># Your pattern here!<br>pattern = r&quot;\&quot;?([-a-zA-Z0-9.`?{}]+@\w+\.\w+)\&quot;?&quot;<br>test_email(pattern)</pre><pre>//Outputs<br>Pass<br>Pass<br>Pass</pre><h3>Exception Handling</h3><p>When programming, errors happen. It’s just a fact of life. Perhaps the user gave bad input. Maybe a network resource was unavailable. Maybe the program ran out of memory. Or the programmer may have even made a mistake!</p><p>But sometimes you don’t want exceptions to completely stop the program. You might want to do something special when an exception is raised. This is done in a try/except block.</p><p>Example:</p><pre>def do_stuff_with_number(n):<br>        print(n)</pre><pre>the_list = (1, 2, 3, 4, 5)</pre><pre>for i in range(20):<br>    try:<br>        do_stuff_with_number(the_list[i])<br>    except IndexError: # Raised when accessing a non-existing index of a list<br>        do_stuff_with_number(0)</pre><pre>//outputs<br>1<br>2<br>3<br>4<br>5<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0</pre><h3>Sets</h3><p>Sets are lists with no duplicate entries. Let’s say you want to collect a list of words used in a paragraph:</p><pre>print(set(&quot;my name is Eric and Eric is my name&quot;.split()))<br>//outputs<br>{&#39;Eric&#39;, &#39;is&#39;, &#39;name&#39;, &#39;and&#39;, &#39;my&#39;}</pre><pre>a = set([&quot;Jake&quot;, &quot;John&quot;, &quot;Eric&quot;])<br>print(a)<br>//outputs<br>{&#39;Eric&#39;, &#39;John&#39;, &#39;Jake&#39;}</pre><pre>b = set([&quot;John&quot;, &quot;Jill&quot;])<br>print(b)<br>//outputs<br>{&#39;John&#39;, &#39;Jill&#39;}</pre><h3>The different methods are:</h3><ul><li>intersection()</li><li>symmetric_difference()</li><li>difference()</li><li>union()</li></ul><pre>a = set([&quot;Jake&quot;, &quot;John&quot;, &quot;Eric&quot;])<br>b = set([&quot;John&quot;, &quot;Jill&quot;])</pre><pre>print(a.intersection(b))<br>print(b.intersection(a))</pre><pre>//outputs <br>{&#39;John&#39;}<br>{&#39;John&#39;}</pre><pre>a = set([&quot;Jake&quot;, &quot;John&quot;, &quot;Eric&quot;])<br>b = set([&quot;John&quot;, &quot;Jill&quot;])</pre><pre>print(a.symmetric_difference(b))<br>print(b.symmetric_difference(a))</pre><pre>//outputs<br>{&#39;Eric&#39;, &#39;Jake&#39;, &#39;Jill&#39;}<br>{&#39;Eric&#39;, &#39;Jill&#39;, &#39;Jake&#39;}<br></pre><pre>a = set([&quot;Jake&quot;, &quot;John&quot;, &quot;Eric&quot;])<br>b = set([&quot;John&quot;, &quot;Jill&quot;])</pre><pre>print(a.difference(b))<br>print(b.difference(a))</pre><pre>//Outputs<br>{&#39;Eric&#39;, &#39;Jake&#39;}<br>{&#39;Jill&#39;}</pre><pre>a = set([&quot;Jake&quot;, &quot;John&quot;, &quot;Eric&quot;])<br>b = set([&quot;John&quot;, &quot;Jill&quot;])</pre><pre>print(a.union(b))</pre><pre>//Outputs<br>{&#39;Jill&#39;, &#39;Eric&#39;, &#39;John&#39;, &#39;Jake&#39;}</pre><h3>Serialization</h3><p>Data serialization is the concept of converting structured data into a format that allows it to be shared or stored in such a way that its original structure to be recovered. In some cases, the secondary intention of data serialization is to minimize the size of the serialized data which then minimizes disk space or bandwidth requirements.</p><h3>Pickle</h3><p>The native data serialization module for Python is called <a href="https://docs.python.org/2/library/pickle.html">Pickle</a>.</p><p>Example:</p><pre>import pickle</pre><pre>//Here&#39;s an example dict<br>grades = { &#39;Alice&#39;: 89, &#39;Bob&#39;: 72, &#39;Charles&#39;: 87 }</pre><pre>//Use dumps to convert the object to a serialized string<br>serial_grades = pickle.dumps( grades )<br>print(serial_grades);</pre><pre>//Use loads to de-serialize an object<br>received_grades = pickle.loads( serial_grades )<br>print(received_grades)</pre><pre>//Outputs<br>b&#39;\x80\x03}q\x00(X\x07\x00\x00\x00Charlesq\x01KWX\x03\x00\x00\x00Bobq\x02KHX\x05\x00\x00\x00Aliceq\x03KYu.&#39;<br>{&#39;Charles&#39;: 87, &#39;Bob&#39;: 72, &#39;Alice&#39;: 89}</pre><h3>Partial functions</h3><p>You can create partial functions in python by using the partial function from the function tools library.</p><p>Partial functions allow one to derive a function with x parameters to a function with fewer parameters and fixed values set for the more limited function.</p><p>Example:</p><pre>from functools import partial</pre><pre>def multiply(x,y):<br>        return x * y</pre><pre># create a new function that multiplies by 2<br>dbl = partial(multiply,2)<br>print(dbl(4))</pre><pre>//outputs<br>8</pre><p>Note: An important note: the default values will start replacing variables from the left. The 2 will replace x. y will equal 4 when dbl(4) is called. It does not make a difference in this example, but it does in the example above.</p><h3>Code Introspection</h3><p>Code introspection is the ability to examine classes, functions and keywords to know what they are, what they do and what they know.</p><p>Python provides several functions and utilities for code introspection.</p><ul><li>help()</li><li>dir()</li><li>hasattr()</li><li>id()</li><li>type()</li><li>repr()</li><li>callable()</li><li>issubclass()</li><li>isinstance()</li><li>__doc__</li><li>__name__</li></ul><p>Note: Often the most important one is the help function since you can use it to find what other functions do.</p><pre># Define the Vehicle class<br>class Vehicle:<br>    name = &quot;&quot;<br>    kind = &quot;car&quot;<br>    color = &quot;&quot;<br>    value = 100.00<br>    def description(self):<br>        desc_str = &quot;%s is a %s %s worth $%.2f.&quot; % (self.name, self.color, self.kind, self.value)<br>        return desc_str</pre><pre>//Print a list of all attributes of the Vehicle class.<br>print(dir(Vehicle))<br></pre><pre>//Outputs<br>[&#39;__class__&#39;, &#39;__delattr__&#39;, &#39;__dict__&#39;, &#39;__dir__&#39;, <br>&#39;__doc__&#39;, &#39;__eq__&#39;, &#39;__format__&#39;, &#39;__ge__&#39;, &#39;__getattribute__&#39;, <br>&#39;__gt__&#39;, &#39;__hash__&#39;, &#39;__init__&#39;, &#39;__le__&#39;, &#39;__lt__&#39;, &#39;__module__&#39;, <br>&#39;__ne__&#39;, &#39;__new__&#39;, &#39;__reduce__&#39;, &#39;__reduce_ex__&#39;, &#39;__repr__&#39;, &#39;__setattr__&#39;, <br>&#39;__sizeof__&#39;, &#39;__str__&#39;, &#39;__subclasshook__&#39;, &#39;__weakref__&#39;, <br>&#39;color&#39;, &#39;description&#39;, &#39;kind&#39;, &#39;name&#39;, &#39;value&#39;]</pre><h3>Closures</h3><p>A Closure is a function object that remembers values in enclosing scopes even if they are not present in memory.</p><p>Firstly, a Nested Function is a function defined inside another function. It’s very important to note that the nested functions can access the variables of the enclosing scope. However, at least in python, they are only read-only. However, one can use the “nonlocal” keyword explicitly with these variables to modify them.</p><h3>Before using nonlocal</h3><pre>def transmit_to_space(message):<br>    &quot;This is the enclosing function&quot;<br>    def data_transmitter():<br>        &quot;The nested function&quot;<br>        print(message)</pre><pre>    data_transmitter()</pre><pre>print(transmit_to_space(&quot;Test message&quot;))</pre><pre>//Output<br>Test message<br>None</pre><h3>After using nonlocal</h3><pre>def print_msg(number):<br>    def printer():<br>        &quot;Here we are using the nonlocal keyword&quot;<br>        nonlocal number<br>        number=3<br>        print(number)<br>    printer()<br>    print(number)</pre><pre>print_msg(9)</pre><pre>//Outputs<br>3<br>3</pre><p>Without the nonlocal keyword, the output would be “3 9”, however, with its usage, we get “3 3”, that is the value of the “number” variable gets modified.</p><p>ADVANTAGE: Closures can avoid the use of global variables and provides some form of data hiding. (Eg. When there are few methods in a class, use closures instead).</p><h3>Inheritance</h3><ul><li>Classes can inherit from other classes.</li><li>A class can inherit attributes and behaviour methods from another class, called the superclass.</li><li>A class that inherits from a superclass is called a subclass, also called heir class or child class.</li><li>Superclasses are sometimes called ancestors as well. There exists a hierarchical relationship between classes. It’s similar to relationships or categorizations that we know from real life.</li></ul><pre>class Person:</pre><pre>    def __init__(self, first, last):<br>        self.firstname = first<br>        self.lastname = last</pre><pre>    def Name(self):<br>        return self.firstname + &quot; &quot; + self.lastname</pre><pre>class Employee(Person):</pre><pre>    def __init__(self, first, last, staffnum):<br>        Person.__init__(self,first, last)<br>        self.staffnumber = staffnum</pre><pre>    def GetEmployee(self):<br>        return self.Name() + &quot;, &quot; +  self.staffnumber</pre><pre>x = Person(&quot;Marge&quot;, &quot;Simpson&quot;)<br>y = Employee(&quot;Homer&quot;, &quot;Simpson&quot;, &quot;1007&quot;)</pre><pre>print(x.Name())<br>print(y.GetEmployee())<br></pre><pre>//Output<br>Marge Simpson<br>Homer Simpson, 1007</pre><p>The __init__ method of our Employee class explicitly invokes the __init__method of the Person class. We could have used super instead. super().__init__(first, last) is automatically replaced by a call to the superclasses method, in this case, __init__:</p><pre>def __init__(self, first, last, staffnum):<br>        super().__init__(first, last)<br>        self.staffnumber = staffnum</pre><p>Note:</p><p>Please note that we used super()) without arguments. This is only possible in Python3. We could have written “super(Employee, self).__init__(first, last, age)” which still works in Python3 and is compatible with Python2.</p><h3>To be continued……………………</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b6a5145f251" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>