Skip to content

Instantly share code, notes, and snippets.

View raj1rana's full-sized avatar
😃
I may be slow to respond.

Rajendra Singh Rana raj1rana

😃
I may be slow to respond.
View GitHub Profile

Here are examples of how to change data types in Python using type conversion functions:


1. Converting to Integer (int)

  • From string to integer:
    x = "42"
    result = int(x)  # Converts string to integer
    print(result)  # Output: 42

Here is a comprehensive list of Python data types along with examples for each:

1. Numeric Types

  • int (Integer): Whole numbers
    • Example: x = 10
  • float (Floating Point): Numbers with decimal points
    • Example: y = 3.14
  • complex (Complex Numbers): Numbers with real and imaginary parts
    • Example: z = 2 + 3j

Python provides a wide range of built-in functions and methods to work with lists. Here’s a comprehensive list of them, grouped by functionality:


1. Adding Elements

  • append(): Adds a single element to the end of the list.
    fruits = ["apple", "banana"]
    fruits.append("cherry")
    print(fruits)  # Output: ["apple", "banana", "cherry"]
/*! For license information please see choices.min.js.LICENSE.txt */
!function(){"use strict";var e={282:function(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.clearChoices=t.activateChoices=t.filterChoices=t.addChoice=void 0;var n=i(883);t.addChoice=function(e){var t=e.value,i=e.label,r=e.id,s=e.groupId,o=e.disabled,a=e.elementId,c=e.customProperties,l=e.placeholder,h=e.keyCode;return{type:n.ACTION_TYPES.ADD_CHOICE,value:t,label:i,id:r,groupId:s,disabled:o,elementId:a,customProperties:c,placeholder:l,keyCode:h}},t.filterChoices=function(e){return{type:n.ACTION_TYPES.FILTER_CHOICES,results:e}},t.activateChoices=function(e){return void 0===e&&(e=!0),{type:n.ACTION_TYPES.ACTIVATE_CHOICES,active:e}},t.clearChoices=function(){return{type:n.ACTION_TYPES.CLEAR_CHOICES}}},783:function(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.addGroup=void 0;var n=i(883);t.addGroup=function(e){var t=e.value,i=e.id,r=e.active,s=e.disabled;return{type:n.ACTION_TYPES.ADD_GROUP,value:t,id:i,active:r,disabled:
/* flatpickr v4.6.13,, @license MIT */
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).flatpickr=n()}(this,(function(){"use strict";var e=function(){return(e=Object.assign||function(e){for(var n,t=1,a=arguments.length;t<a;t++)for(var i in n=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e}).apply(this,arguments)};function n(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var a=Array(e),i=0;for(n=0;n<t;n++)for(var o=arguments[n],r=0,l=o.length;r<l;r++,i++)a[i]=o[r];return a}var t=["onChange","onClose","onDayCreate","onDestroy","onKeyDown","onMonthChange","onOpen","onParseConfig","onReady","onValueUpdate","onYearChange","onPreCalendarPosition"],a={_disable:[],allowInput:!1,allowInvalidPreload:!1,altFormat:"F j, Y",altInput:!1,altInputClass:"form-control input",animate:"object"==typeof window&&-1===window.navigator.userAgent.i
@raj1rana
raj1rana / create a PV.md
Created May 20, 2022 09:20
create a presistence volume in k8

to create a volume in k8 use the following snippet

---
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    generated.by: 8gwifi.org
  name: pvo.0
  namespace: default
@raj1rana
raj1rana / create-service-nodeport.md
Created May 20, 2022 08:32
create service nodeport

to create NodePort service below is the simple snippet to get you started

apiVersion: v1
kind: Service
metadata:
  name: wordpress-service
spec:
  type: NodePort
  selector:
 type: webapp # this is the label of your pod. 
@raj1rana
raj1rana / Kubernetes create and attach secret as env in deployment.md
Last active May 20, 2022 09:37
Kubernetes create and attach secret as env in deployment

Encode the secret texts into base64

    echo  -n 'secret' | base64 

create a secret file

    apiVersion: v1
    kind: Secret
    metadata:
      name: wordpress_secret
#!/usr/bin/env bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
else
create_user(){
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p "$pass" "$username"
[ $? -eq 0 ] && echo "User $username has been added to system!" || echo "Failed to add a user!"
@raj1rana
raj1rana / Python_sheet_create_github_data.py
Last active May 20, 2022 09:37
Create excel sheet with github data
from openpyxl import Workbook
import json
import requests
workbook = Workbook()
sheet = workbook.active
row = 1
########################### VARIABLES #########################################################